diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java index 3e831234e3..d8ca9dcdf3 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java @@ -144,6 +144,8 @@ final class JavaPluginAction implements PluginApplicationAction { .getByName(SpringBootPlugin.DEVELOPMENT_ONLY_CONFIGURATION_NAME); Configuration productionRuntimeClasspath = project.getConfigurations() .getByName(SpringBootPlugin.PRODUCTION_RUNTIME_CLASSPATH_CONFIGURATION_NAME); + Configuration runtimeClasspath = project.getConfigurations() + .getByName(mainSourceSet.getRuntimeClasspathConfigurationName()); Callable classpath = () -> mainSourceSet.getRuntimeClasspath() .minus((developmentOnly.minus(productionRuntimeClasspath))) .filter(new JarTypeFileSpec()); @@ -159,6 +161,7 @@ final class JavaPluginAction implements PluginApplicationAction { ? manifestStartClass : resolveMainClassName.get().readMainClassName())); bootJar.getTargetJavaVersion() .set(project.provider(() -> javaPluginExtension(project).getTargetCompatibility())); + bootJar.resolvedArtifacts(runtimeClasspath.getIncoming().getArtifacts().getResolvedArtifacts()); }); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/WarPluginAction.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/WarPluginAction.java index feb988ed74..2e13827001 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/WarPluginAction.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/WarPluginAction.java @@ -74,10 +74,12 @@ class WarPluginAction implements PluginApplicationAction { .getByName(SpringBootPlugin.DEVELOPMENT_ONLY_CONFIGURATION_NAME); Configuration productionRuntimeClasspath = project.getConfigurations() .getByName(SpringBootPlugin.PRODUCTION_RUNTIME_CLASSPATH_CONFIGURATION_NAME); - Callable classpath = () -> project.getExtensions() + SourceSet mainSourceSet = project.getExtensions() .getByType(SourceSetContainer.class) - .getByName(SourceSet.MAIN_SOURCE_SET_NAME) - .getRuntimeClasspath() + .getByName(SourceSet.MAIN_SOURCE_SET_NAME); + Configuration runtimeClasspath = project.getConfigurations() + .getByName(mainSourceSet.getRuntimeClasspathConfigurationName()); + Callable classpath = () -> mainSourceSet.getRuntimeClasspath() .minus(providedRuntimeConfiguration(project)) .minus((developmentOnly.minus(productionRuntimeClasspath))) .filter(new JarTypeFileSpec()); @@ -97,6 +99,7 @@ class WarPluginAction implements PluginApplicationAction { ? manifestStartClass : resolveMainClassName.get().readMainClassName())); bootWar.getTargetJavaVersion() .set(project.provider(() -> javaPluginExtension(project).getTargetCompatibility())); + bootWar.resolvedArtifacts(runtimeClasspath.getIncoming().getArtifacts().getResolvedArtifacts()); }); bootWarProvider.map(War::getClasspath); return bootWarProvider; diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootArchive.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootArchive.java index 85b37322bf..329e290709 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootArchive.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootArchive.java @@ -16,13 +16,17 @@ package org.springframework.boot.gradle.tasks.bundling; +import java.util.Set; + import org.gradle.api.Action; import org.gradle.api.JavaVersion; import org.gradle.api.Project; import org.gradle.api.Task; +import org.gradle.api.artifacts.result.ResolvedArtifactResult; import org.gradle.api.file.FileCollection; import org.gradle.api.file.FileTreeElement; import org.gradle.api.provider.Property; +import org.gradle.api.provider.Provider; import org.gradle.api.specs.Spec; import org.gradle.api.tasks.Classpath; import org.gradle.api.tasks.Input; @@ -120,4 +124,13 @@ public interface BootArchive extends Task { @Optional Property getTargetJavaVersion(); + /** + * Registers the given lazily provided {@code resolvedArtifacts}. They are used to map + * from the files in the {@link #getClasspath classpath} to their dependency + * coordinates. + * @param resolvedArtifacts the lazily provided resolved artifacts + * @since 3.0.7 + */ + void resolvedArtifacts(Provider> resolvedArtifacts); + } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java index b9dfd52a4d..2b2d1cfa2e 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java @@ -18,12 +18,13 @@ package org.springframework.boot.gradle.tasks.bundling; import java.io.File; import java.util.Collections; +import java.util.Set; import java.util.concurrent.Callable; import java.util.function.Function; import org.gradle.api.Action; import org.gradle.api.Project; -import org.gradle.api.artifacts.ResolvableDependencies; +import org.gradle.api.artifacts.result.ResolvedArtifactResult; import org.gradle.api.file.CopySpec; import org.gradle.api.file.FileCollection; import org.gradle.api.file.FileCopyDetails; @@ -58,8 +59,6 @@ public abstract class BootJar extends Jar implements BootArchive { private static final String CLASSPATH_INDEX = "BOOT-INF/classpath.idx"; - private final ResolvedDependencies resolvedDependencies = new ResolvedDependencies(); - private final BootArchiveSupport support; private final CopySpec bootInfSpec; @@ -70,6 +69,8 @@ public abstract class BootJar extends Jar implements BootArchive { private final Provider projectVersion; + private final ResolvedDependencies resolvedDependencies; + private FileCollection classpath; /** @@ -82,16 +83,9 @@ public abstract class BootJar extends Jar implements BootArchive { this.layered = project.getObjects().newInstance(LayeredSpec.class); configureBootInfSpec(this.bootInfSpec); getMainSpec().with(this.bootInfSpec); - project.getConfigurations().all((configuration) -> { - ResolvableDependencies incoming = configuration.getIncoming(); - incoming.afterResolve((resolvableDependencies) -> { - if (resolvableDependencies == incoming) { - this.resolvedDependencies.processConfiguration(project, configuration); - } - }); - }); this.projectName = project.provider(project::getName); this.projectVersion = project.provider(project::getVersion); + this.resolvedDependencies = new ResolvedDependencies(project); } private void configureBootInfSpec(CopySpec bootInfSpec) { @@ -123,6 +117,16 @@ public abstract class BootJar extends Jar implements BootArchive { }); } + @Override + public void resolvedArtifacts(Provider> resolvedArtifacts) { + this.resolvedDependencies.resolvedArtifacts(resolvedArtifacts); + } + + @Nested + ResolvedDependencies getResolvedDependencies() { + return this.resolvedDependencies; + } + @Override public void copy() { this.support.configureManifest(getManifest(), getMainClass().get(), CLASSES_DIRECTORY, LIB_DIRECTORY, @@ -291,11 +295,6 @@ public abstract class BootJar extends Jar implements BootArchive { return callable; } - @Internal - ResolvedDependencies getResolvedDependencies() { - return this.resolvedDependencies; - } - private final class LibrarySpec implements Spec { @Override diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootWar.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootWar.java index fac4f6969f..47ce5f0c54 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootWar.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootWar.java @@ -17,12 +17,13 @@ package org.springframework.boot.gradle.tasks.bundling; import java.util.Collections; +import java.util.Set; import java.util.concurrent.Callable; import java.util.function.Function; import org.gradle.api.Action; import org.gradle.api.Project; -import org.gradle.api.artifacts.ResolvableDependencies; +import org.gradle.api.artifacts.result.ResolvedArtifactResult; import org.gradle.api.file.CopySpec; import org.gradle.api.file.FileCollection; import org.gradle.api.file.FileCopyDetails; @@ -31,7 +32,6 @@ import org.gradle.api.internal.file.copy.CopyAction; import org.gradle.api.provider.Provider; import org.gradle.api.specs.Spec; import org.gradle.api.tasks.Classpath; -import org.gradle.api.tasks.Internal; import org.gradle.api.tasks.Nested; import org.gradle.api.tasks.Optional; import org.gradle.api.tasks.bundling.War; @@ -62,14 +62,14 @@ public abstract class BootWar extends War implements BootArchive { private final BootArchiveSupport support; - private final ResolvedDependencies resolvedDependencies = new ResolvedDependencies(); - private final LayeredSpec layered; private final Provider projectName; private final Provider projectVersion; + private final ResolvedDependencies resolvedDependencies; + private FileCollection providedClasspath; /** @@ -82,22 +82,25 @@ public abstract class BootWar extends War implements BootArchive { getWebInf().into("lib-provided", fromCallTo(this::getProvidedLibFiles)); this.support.moveModuleInfoToRoot(getRootSpec()); getRootSpec().eachFile(this.support::excludeNonZipLibraryFiles); - project.getConfigurations().all((configuration) -> { - ResolvableDependencies incoming = configuration.getIncoming(); - incoming.afterResolve((resolvableDependencies) -> { - if (resolvableDependencies == incoming) { - this.resolvedDependencies.processConfiguration(project, configuration); - } - }); - }); this.projectName = project.provider(project::getName); this.projectVersion = project.provider(project::getVersion); + this.resolvedDependencies = new ResolvedDependencies(project); } private Object getProvidedLibFiles() { return (this.providedClasspath != null) ? this.providedClasspath : Collections.emptyList(); } + @Override + public void resolvedArtifacts(Provider> resolvedArtifacts) { + this.resolvedDependencies.resolvedArtifacts(resolvedArtifacts); + } + + @Nested + ResolvedDependencies getResolvedDependencies() { + return this.resolvedDependencies; + } + @Override public void copy() { this.support.configureManifest(getManifest(), getMainClass().get(), CLASSES_DIRECTORY, LIB_DIRECTORY, @@ -240,11 +243,6 @@ public abstract class BootWar extends War implements BootArchive { return launchScript; } - @Internal - ResolvedDependencies getResolvedDependencies() { - return this.resolvedDependencies; - } - /** * Syntactic sugar that makes {@link CopySpec#into} calls a little easier to read. * @param the result type diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/ResolvedDependencies.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/ResolvedDependencies.java index 630f15794b..8245e2eab1 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/ResolvedDependencies.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/ResolvedDependencies.java @@ -17,23 +17,29 @@ package org.springframework.boot.gradle.tasks.bundling; import java.io.File; -import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; import org.gradle.api.Project; -import org.gradle.api.artifacts.Configuration; -import org.gradle.api.artifacts.LenientConfiguration; -import org.gradle.api.artifacts.ModuleVersionIdentifier; -import org.gradle.api.artifacts.ResolvedArtifact; import org.gradle.api.artifacts.ResolvedConfiguration; +import org.gradle.api.artifacts.component.ComponentArtifactIdentifier; +import org.gradle.api.artifacts.component.ComponentIdentifier; +import org.gradle.api.artifacts.component.ModuleComponentIdentifier; +import org.gradle.api.artifacts.component.ProjectComponentIdentifier; +import org.gradle.api.artifacts.result.ResolvedArtifactResult; +import org.gradle.api.provider.ListProperty; +import org.gradle.api.provider.Provider; +import org.gradle.api.tasks.Classpath; +import org.gradle.api.tasks.Input; +import org.gradle.internal.component.external.model.ModuleComponentArtifactIdentifier; import org.springframework.boot.loader.tools.LibraryCoordinates; /** - * Tracks and provides details of resolved dependencies in the project so we can find - * {@link LibraryCoordinates}. + * Maps from {@link File} to {@link ComponentArtifactIdentifier}. * * @author Madhura Bhave * @author Scott Frederick @@ -43,93 +49,76 @@ import org.springframework.boot.loader.tools.LibraryCoordinates; */ class ResolvedDependencies { - private final Map configurationDependencies = new LinkedHashMap<>(); + private final Map projectCoordinatesByPath; - private String projectId(Project project) { - return project.getGroup() + ":" + project.getName() + ":" + project.getVersion(); + private final ListProperty artifactIds; + + private final ListProperty artifactFiles; + + ResolvedDependencies(Project project) { + this.artifactIds = project.getObjects().listProperty(ComponentArtifactIdentifier.class); + this.artifactFiles = project.getObjects().listProperty(File.class); + this.projectCoordinatesByPath = projectCoordinatesByPath(project); } - void processConfiguration(Project project, Configuration configuration) { - Set localProjectIds = project.getRootProject() + private static Map projectCoordinatesByPath(Project project) { + return project.getRootProject() .getAllprojects() .stream() - .map(this::projectId) - .collect(Collectors.toSet()); - this.configurationDependencies.put(configuration, - new ResolvedConfigurationDependencies(localProjectIds, configuration.getResolvedConfiguration())); + .collect(Collectors.toMap(Project::getPath, ResolvedDependencies::libraryCoordinates)); } - DependencyDescriptor find(File file) { - for (ResolvedConfigurationDependencies dependencies : this.configurationDependencies.values()) { - DependencyDescriptor dependency = dependencies.find(file); - if (dependency != null) { - return dependency; - } - } - return null; + private static LibraryCoordinates libraryCoordinates(Project project) { + return LibraryCoordinates.of(Objects.toString(project.getGroup()), project.getName(), + Objects.toString(project.getVersion())); } - /** - * Stores details of resolved configuration dependencies. - */ - private static class ResolvedConfigurationDependencies { - - private final Map dependencies = new LinkedHashMap<>(); - - ResolvedConfigurationDependencies(Set projectDependencyIds, - ResolvedConfiguration resolvedConfiguration) { - if (!resolvedConfiguration.hasError()) { - LenientConfiguration lenientConfiguration = resolvedConfiguration.getLenientConfiguration(); - // Ensure that all files are resolved, allowing Gradle to resolve in - // parallel if they are not - lenientConfiguration.getFiles(); - for (ResolvedArtifact resolvedArtifact : lenientConfiguration.getArtifacts()) { - ModuleVersionIdentifier id = resolvedArtifact.getModuleVersion().getId(); - boolean projectDependency = projectDependencyIds - .contains(id.getGroup() + ":" + id.getName() + ":" + id.getVersion()); - this.dependencies.put(resolvedArtifact.getFile(), new DependencyDescriptor( - new ModuleVersionIdentifierLibraryCoordinates(id), projectDependency)); - } - } - } - - DependencyDescriptor find(File file) { - return this.dependencies.get(file); - } - + @Input + ListProperty getArtifactIds() { + return this.artifactIds; } - /** - * Adapts a {@link ModuleVersionIdentifier} to {@link LibraryCoordinates}. - */ - private static class ModuleVersionIdentifierLibraryCoordinates implements LibraryCoordinates { - - private final ModuleVersionIdentifier identifier; + @Classpath + ListProperty getArtifactFiles() { + return this.artifactFiles; + } - ModuleVersionIdentifierLibraryCoordinates(ModuleVersionIdentifier identifier) { - this.identifier = identifier; - } + void resolvedArtifacts(Provider> resolvedArtifacts) { + this.artifactFiles.addAll(resolvedArtifacts + .map((artifacts) -> artifacts.stream().map(ResolvedArtifactResult::getFile).collect(Collectors.toList()))); + this.artifactIds.addAll(resolvedArtifacts + .map((artifacts) -> artifacts.stream().map(ResolvedArtifactResult::getId).collect(Collectors.toList()))); + } - @Override - public String getGroupId() { - return this.identifier.getGroup(); + DependencyDescriptor find(File file) { + ComponentArtifactIdentifier id = findArtifactIdentifier(file); + if (id == null) { + return null; } - - @Override - public String getArtifactId() { - return this.identifier.getName(); + if (id instanceof ModuleComponentArtifactIdentifier moduleComponentId) { + ModuleComponentIdentifier moduleId = moduleComponentId.getComponentIdentifier(); + return new DependencyDescriptor( + LibraryCoordinates.of(moduleId.getGroup(), moduleId.getModule(), moduleId.getVersion()), false); } - - @Override - public String getVersion() { - return this.identifier.getVersion(); + ComponentIdentifier componentIdentifier = id.getComponentIdentifier(); + if (componentIdentifier instanceof ProjectComponentIdentifier projectComponentId) { + String projectPath = projectComponentId.getProjectPath(); + LibraryCoordinates projectCoordinates = this.projectCoordinatesByPath.get(projectPath); + if (projectCoordinates != null) { + return new DependencyDescriptor(projectCoordinates, true); + } } + return null; + } - @Override - public String toString() { - return this.identifier.toString(); + private ComponentArtifactIdentifier findArtifactIdentifier(File file) { + List files = this.artifactFiles.get(); + for (int i = 0; i < files.size(); i++) { + if (file.equals(files.get(i))) { + return this.artifactIds.get().get(i); + } } - + return null; } /** diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveTests.java index 532a65d245..ec338420f1 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveTests.java @@ -47,21 +47,17 @@ import org.apache.commons.compress.archivers.zip.ZipFile; import org.gradle.api.Action; import org.gradle.api.DomainObjectSet; import org.gradle.api.Project; +import org.gradle.api.artifacts.ArtifactCollection; import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.DependencySet; -import org.gradle.api.artifacts.LenientConfiguration; -import org.gradle.api.artifacts.ModuleVersionIdentifier; import org.gradle.api.artifacts.ProjectDependency; import org.gradle.api.artifacts.ResolvableDependencies; -import org.gradle.api.artifacts.ResolvedArtifact; -import org.gradle.api.artifacts.ResolvedConfiguration; -import org.gradle.api.artifacts.ResolvedModuleVersion; -import org.gradle.api.artifacts.component.ComponentArtifactIdentifier; import org.gradle.api.artifacts.component.ModuleComponentIdentifier; -import org.gradle.api.artifacts.component.ProjectComponentIdentifier; +import org.gradle.api.artifacts.result.ResolvedArtifactResult; import org.gradle.api.internal.file.archive.ZipCopyAction; import org.gradle.api.tasks.bundling.AbstractArchiveTask; import org.gradle.api.tasks.bundling.Jar; +import org.gradle.internal.component.external.model.ModuleComponentArtifactIdentifier; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -718,23 +714,21 @@ abstract class AbstractBootArchiveTests { this.task.classpath(classesJavaMain, resourcesMain, jarFile("first-library.jar"), jarFile("second-library.jar"), jarFile("third-library-SNAPSHOT.jar"), jarFile("fourth-library.jar"), jarFile("first-project-library.jar"), jarFile("second-project-library-SNAPSHOT.jar")); - Set artifacts = new LinkedHashSet<>(); - artifacts.add(mockLibraryArtifact("first-library.jar", "com.example", "first-library", "1.0.0")); - artifacts.add(mockLibraryArtifact("second-library.jar", "com.example", "second-library", "1.0.0")); - artifacts - .add(mockLibraryArtifact("third-library-SNAPSHOT.jar", "com.example", "third-library", "1.0.0.SNAPSHOT")); - artifacts.add(mockLibraryArtifact("fourth-library.jar", "com.example", "fourth-library", "1.0.0")); - artifacts - .add(mockProjectArtifact("first-project-library.jar", "com.example", "first-project-library", "1.0.0")); - artifacts.add(mockProjectArtifact("second-project-library-SNAPSHOT.jar", "com.example", + Set resolvedArtifacts = new LinkedHashSet<>(); + resolvedArtifacts.add(mockArtifact("first-library.jar", "com.example", "first-library", "1.0.0")); + resolvedArtifacts.add(mockArtifact("second-library.jar", "com.example", "second-library", "1.0.0")); + resolvedArtifacts + .add(mockArtifact("third-library-SNAPSHOT.jar", "com.example", "third-library", "1.0.0.SNAPSHOT")); + resolvedArtifacts.add(mockArtifact("fourth-library.jar", "com.example", "fourth-library", "1.0.0")); + resolvedArtifacts + .add(mockArtifact("first-project-library.jar", "com.example", "first-project-library", "1.0.0")); + resolvedArtifacts.add(mockArtifact("second-project-library-SNAPSHOT.jar", "com.example", "second-project-library", "1.0.0.SNAPSHOT")); - ResolvedConfiguration resolvedConfiguration = mock(ResolvedConfiguration.class); - LenientConfiguration lenientConfiguration = mock(LenientConfiguration.class); - given(resolvedConfiguration.getLenientConfiguration()).willReturn(lenientConfiguration); - given(lenientConfiguration.getArtifacts()).willReturn(artifacts); - Configuration configuration = mock(Configuration.class); - given(configuration.getResolvedConfiguration()).willReturn(resolvedConfiguration); + ArtifactCollection artifacts = mock(ArtifactCollection.class); + given(artifacts.getResolvedArtifacts()).willReturn(this.project.provider(() -> resolvedArtifacts)); ResolvableDependencies resolvableDependencies = mock(ResolvableDependencies.class); + given(resolvableDependencies.getArtifacts()).willReturn(artifacts); + Configuration configuration = mock(Configuration.class); given(configuration.getIncoming()).willReturn(resolvableDependencies); DependencySet dependencies = mock(DependencySet.class); DomainObjectSet projectDependencies = mock(DomainObjectSet.class); @@ -757,37 +751,21 @@ abstract class AbstractBootArchiveTests { FileCopyUtils.copy("override=%s\n".formatted(override).getBytes(StandardCharsets.ISO_8859_1), target); } - abstract void populateResolvedDependencies(Configuration configuration); - - private ResolvedArtifact mockLibraryArtifact(String fileName, String group, String module, String version) { - ModuleComponentIdentifier moduleComponentIdentifier = mock(ModuleComponentIdentifier.class); - ComponentArtifactIdentifier libraryArtifactId = mock(ComponentArtifactIdentifier.class); - given(libraryArtifactId.getComponentIdentifier()).willReturn(moduleComponentIdentifier); - ResolvedArtifact libraryArtifact = mockArtifact(fileName, group, module, version); - given(libraryArtifact.getId()).willReturn(libraryArtifactId); - return libraryArtifact; - } - - private ResolvedArtifact mockProjectArtifact(String fileName, String group, String module, String version) { - ProjectComponentIdentifier projectComponentIdentifier = mock(ProjectComponentIdentifier.class); - ComponentArtifactIdentifier projectArtifactId = mock(ComponentArtifactIdentifier.class); - given(projectArtifactId.getComponentIdentifier()).willReturn(projectComponentIdentifier); - ResolvedArtifact projectArtifact = mockArtifact(fileName, group, module, version); - given(projectArtifact.getId()).willReturn(projectArtifactId); - return projectArtifact; + private void populateResolvedDependencies(Configuration configuration) { + getTask().resolvedArtifacts(configuration.getIncoming().getArtifacts().getResolvedArtifacts()); } - private ResolvedArtifact mockArtifact(String fileName, String group, String module, String version) { - ModuleVersionIdentifier moduleVersionIdentifier = mock(ModuleVersionIdentifier.class); - given(moduleVersionIdentifier.getGroup()).willReturn(group); - given(moduleVersionIdentifier.getName()).willReturn(module); - given(moduleVersionIdentifier.getVersion()).willReturn(version); - ResolvedModuleVersion moduleVersion = mock(ResolvedModuleVersion.class); - given(moduleVersion.getId()).willReturn(moduleVersionIdentifier); - ResolvedArtifact libraryArtifact = mock(ResolvedArtifact.class); + private ResolvedArtifactResult mockArtifact(String fileName, String group, String module, String version) { + ModuleComponentArtifactIdentifier moduleId = mock(ModuleComponentArtifactIdentifier.class); + ModuleComponentIdentifier componentId = mock(ModuleComponentIdentifier.class); + given(moduleId.getComponentIdentifier()).willReturn(componentId); + given(componentId.getGroup()).willReturn(group); + given(componentId.getModule()).willReturn(module); + given(componentId.getVersion()).willReturn(version); + ResolvedArtifactResult libraryArtifact = mock(ResolvedArtifactResult.class); File file = new File(this.temp, fileName).getAbsoluteFile(); given(libraryArtifact.getFile()).willReturn(file); - given(libraryArtifact.getModuleVersion()).willReturn(moduleVersion); + given(libraryArtifact.getId()).willReturn(moduleId); return libraryArtifact; } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarTests.java index 38d5f09781..5355e1ba79 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarTests.java @@ -22,7 +22,6 @@ import java.util.jar.JarFile; import org.gradle.api.Action; import org.gradle.api.JavaVersion; -import org.gradle.api.artifacts.Configuration; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -217,11 +216,6 @@ class BootJarTests extends AbstractBootArchiveTests { getTask().layered(action); } - @Override - void populateResolvedDependencies(Configuration configuration) { - getTask().getResolvedDependencies().processConfiguration(getTask().getProject(), configuration); - } - @Override protected void executeTask() { getTask().copy(); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootWarTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootWarTests.java index e2c280b242..e53080ca77 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootWarTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootWarTests.java @@ -22,7 +22,6 @@ import java.util.jar.JarFile; import org.gradle.api.Action; import org.gradle.api.JavaVersion; -import org.gradle.api.artifacts.Configuration; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -157,11 +156,6 @@ class BootWarTests extends AbstractBootArchiveTests { getTask().copy(); } - @Override - void populateResolvedDependencies(Configuration configuration) { - getTask().getResolvedDependencies().processConfiguration(getTask().getProject(), configuration); - } - @Override void applyLayered(Action action) { getTask().layered(action);