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 adf3a0968e..59e972401e 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 @@ -22,6 +22,7 @@ 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.file.CopySpec; import org.gradle.api.file.FileCollection; @@ -72,15 +73,16 @@ public class BootJar extends Jar implements BootArchive { */ public BootJar() { this.support = new BootArchiveSupport(LAUNCHER, new LibrarySpec(), new ZipCompressionResolver()); - this.bootInfSpec = getProject().copySpec().into("BOOT-INF"); - this.mainClass = getProject().getObjects().property(String.class); + Project project = getProject(); + this.bootInfSpec = project.copySpec().into("BOOT-INF"); + this.mainClass = project.getObjects().property(String.class); configureBootInfSpec(this.bootInfSpec); getMainSpec().with(this.bootInfSpec); - getProject().getConfigurations().all((configuration) -> { + project.getConfigurations().all((configuration) -> { ResolvableDependencies incoming = configuration.getIncoming(); incoming.afterResolve((resolvableDependencies) -> { if (resolvableDependencies == incoming) { - this.resolvedDependencies.processConfiguration(configuration); + this.resolvedDependencies.processConfiguration(project, configuration); } }); }); 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 78ee717398..addcd40215 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 @@ -70,15 +70,16 @@ public class BootWar extends War implements BootArchive { */ public BootWar() { this.support = new BootArchiveSupport(LAUNCHER, new LibrarySpec(), new ZipCompressionResolver()); - this.mainClass = getProject().getObjects().property(String.class); + Project project = getProject(); + this.mainClass = project.getObjects().property(String.class); getWebInf().into("lib-provided", fromCallTo(this::getProvidedLibFiles)); this.support.moveModuleInfoToRoot(getRootSpec()); getRootSpec().eachFile(this.support::excludeNonZipLibraryFiles); - getProject().getConfigurations().all((configuration) -> { + project.getConfigurations().all((configuration) -> { ResolvableDependencies incoming = configuration.getIncoming(); incoming.afterResolve((resolvableDependencies) -> { if (resolvableDependencies == incoming) { - this.resolvedDependencies.processConfiguration(configuration); + this.resolvedDependencies.processConfiguration(project, configuration); } }); }); 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 62548749b9..fc7bdb89db 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 @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,9 +22,9 @@ import java.util.Map; 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.ModuleVersionIdentifier; -import org.gradle.api.artifacts.ProjectDependency; import org.gradle.api.artifacts.ResolvedArtifact; import org.gradle.api.artifacts.ResolvedConfiguration; @@ -44,13 +44,15 @@ class ResolvedDependencies { private final Map configurationDependencies = new LinkedHashMap<>(); - void processConfiguration(Configuration configuration) { - Set projectDependencyIds = configuration.getAllDependencies().withType(ProjectDependency.class).stream() - .map((projectDependency) -> projectDependency.getGroup() + ":" + projectDependency.getName() + ":" - + projectDependency.getVersion()) + private String projectId(Project project) { + return project.getGroup() + ":" + project.getName() + ":" + project.getVersion(); + } + + void processConfiguration(Project project, Configuration configuration) { + Set localProjectIds = project.getRootProject().getAllprojects().stream().map(this::projectId) .collect(Collectors.toSet()); this.configurationDependencies.put(configuration, - new ResolvedConfigurationDependencies(projectDependencyIds, configuration.getResolvedConfiguration())); + new ResolvedConfigurationDependencies(localProjectIds, configuration.getResolvedConfiguration())); } DependencyDescriptor find(File file) { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveIntegrationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveIntegrationTests.java index 624ed4d7bf..aaec5c9f08 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveIntegrationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveIntegrationTests.java @@ -326,6 +326,7 @@ abstract class AbstractBootArchiveIntegrationTests { assertThat(jarFile.getEntry(layerToolsJar)).isNotNull(); assertThat(jarFile.getEntry(this.libPath + "alpha-1.2.3.jar")).isNotNull(); assertThat(jarFile.getEntry(this.libPath + "bravo-1.2.3.jar")).isNotNull(); + assertThat(jarFile.getEntry(this.libPath + "charlie-1.2.3.jar")).isNotNull(); assertThat(jarFile.getEntry(this.libPath + "commons-lang3-3.9.jar")).isNotNull(); assertThat(jarFile.getEntry(this.libPath + "spring-core-5.2.5.RELEASE.jar")).isNotNull(); assertThat(jarFile.getEntry(this.libPath + "spring-jcl-5.2.5.RELEASE.jar")).isNotNull(); @@ -347,8 +348,9 @@ abstract class AbstractBootArchiveIntegrationTests { assertThat(indexedLayers.get("dependencies")).containsExactlyElementsOf(expectedDependencies); assertThat(indexedLayers.get("spring-boot-loader")).containsExactly("org/"); assertThat(indexedLayers.get("snapshot-dependencies")).containsExactlyElementsOf(expectedSnapshotDependencies); - assertThat(indexedLayers.get("application")).containsExactly(getExpectedApplicationLayerContents( - this.classesPath, this.libPath + "alpha-1.2.3.jar", this.libPath + "bravo-1.2.3.jar")); + assertThat(indexedLayers.get("application")) + .containsExactly(getExpectedApplicationLayerContents(this.classesPath, this.libPath + "alpha-1.2.3.jar", + this.libPath + "bravo-1.2.3.jar", this.libPath + "charlie-1.2.3.jar")); BuildResult listLayers = this.gradleBuild.build("listLayers"); assertThat(listLayers.task(":listLayers").getOutcome()).isEqualTo(TaskOutcome.SUCCESS); String listLayersOutput = listLayers.getOutput(); @@ -417,6 +419,7 @@ abstract class AbstractBootArchiveIntegrationTests { assertThat(jarFile.getEntry(layerToolsJar)).isNotNull(); assertThat(jarFile.getEntry(this.libPath + "alpha-1.2.3.jar")).isNotNull(); assertThat(jarFile.getEntry(this.libPath + "bravo-1.2.3.jar")).isNotNull(); + assertThat(jarFile.getEntry(this.libPath + "charlie-1.2.3.jar")).isNotNull(); assertThat(jarFile.getEntry(this.libPath + "commons-lang3-3.9.jar")).isNotNull(); assertThat(jarFile.getEntry(this.libPath + "spring-core-5.2.5.RELEASE.jar")).isNotNull(); assertThat(jarFile.getEntry(this.libPath + "spring-jcl-5.2.5.RELEASE.jar")).isNotNull(); @@ -432,6 +435,7 @@ abstract class AbstractBootArchiveIntegrationTests { Set expectedSubprojectDependencies = new TreeSet<>(); expectedSubprojectDependencies.add(this.libPath + "alpha-1.2.3.jar"); expectedSubprojectDependencies.add(this.libPath + "bravo-1.2.3.jar"); + expectedSubprojectDependencies.add(this.libPath + "charlie-1.2.3.jar"); Set expectedDependencies = new TreeSet<>(); expectedDependencies.add(this.libPath + "spring-core-5.2.5.RELEASE.jar"); expectedDependencies.add(this.libPath + "spring-jcl-5.2.5.RELEASE.jar"); @@ -492,7 +496,7 @@ abstract class AbstractBootArchiveIntegrationTests { private void writeSettingsGradle() { try (PrintWriter writer = new PrintWriter( new FileWriter(new File(this.gradleBuild.getProjectDir(), "settings.gradle")))) { - writer.println("include 'alpha', 'bravo'"); + writer.println("include 'alpha', 'bravo', 'charlie'"); } catch (IOException ex) { throw new RuntimeException(ex); 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 a8fa45c07c..5a99b1fa6a 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 @@ -116,7 +116,7 @@ class BootJarTests extends AbstractBootArchiveTests { @Override void populateResolvedDependencies(Configuration configuration) { - getTask().getResolvedDependencies().processConfiguration(configuration); + getTask().getResolvedDependencies().processConfiguration(getTask().getProject(), configuration); } @Override 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 e162627129..6ffff4a436 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 @@ -116,7 +116,7 @@ class BootWarTests extends AbstractBootArchiveTests { @Override void populateResolvedDependencies(Configuration configuration) { - getTask().getResolvedDependencies().processConfiguration(configuration); + getTask().getResolvedDependencies().processConfiguration(getTask().getProject(), configuration); } @Override diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-multiModuleCustomLayers.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-multiModuleCustomLayers.gradle index 29cc5a3687..f8127b2f3d 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-multiModuleCustomLayers.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-multiModuleCustomLayers.gradle @@ -7,6 +7,11 @@ subprojects { apply plugin: 'java' group = 'org.example.projects' version = '1.2.3' + if (it.name == 'bravo') { + dependencies { + implementation(project(':charlie')) + } + } } bootJar { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-multiModuleImplicitLayers.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-multiModuleImplicitLayers.gradle index bd78e7ce97..ba34cf4d1d 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-multiModuleImplicitLayers.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-multiModuleImplicitLayers.gradle @@ -7,6 +7,11 @@ subprojects { apply plugin: 'java' group = 'org.example.projects' version = '1.2.3' + if (it.name == 'bravo') { + dependencies { + implementation(project(':charlie')) + } + } } bootJar { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootWarIntegrationTests-multiModuleCustomLayers.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootWarIntegrationTests-multiModuleCustomLayers.gradle index d9b51b6bc8..da574d0d15 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootWarIntegrationTests-multiModuleCustomLayers.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootWarIntegrationTests-multiModuleCustomLayers.gradle @@ -8,6 +8,11 @@ subprojects { apply plugin: 'java' group = 'org.example.projects' version = '1.2.3' + if (it.name == 'bravo') { + dependencies { + implementation(project(':charlie')) + } + } } bootWar { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootWarIntegrationTests-multiModuleImplicitLayers.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootWarIntegrationTests-multiModuleImplicitLayers.gradle index f7ce127a7f..cba40d5c3d 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootWarIntegrationTests-multiModuleImplicitLayers.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootWarIntegrationTests-multiModuleImplicitLayers.gradle @@ -8,6 +8,11 @@ subprojects { apply plugin: 'java' group = 'org.example.projects' version = '1.2.3' + if (it.name == 'bravo') { + dependencies { + implementation(project(':charlie')) + } + } } bootWar {