Skip to content

Commit 514aede

Browse files
committed
Merge branch '2.4.x'
Closes gh-25168
2 parents d436521 + 45e6c12 commit 514aede

File tree

10 files changed

+48
-19
lines changed

10 files changed

+48
-19
lines changed

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.function.Function;
2323

2424
import org.gradle.api.Action;
25+
import org.gradle.api.Project;
2526
import org.gradle.api.artifacts.ResolvableDependencies;
2627
import org.gradle.api.file.CopySpec;
2728
import org.gradle.api.file.FileCollection;
@@ -72,15 +73,16 @@ public class BootJar extends Jar implements BootArchive {
7273
*/
7374
public BootJar() {
7475
this.support = new BootArchiveSupport(LAUNCHER, new LibrarySpec(), new ZipCompressionResolver());
75-
this.bootInfSpec = getProject().copySpec().into("BOOT-INF");
76-
this.mainClass = getProject().getObjects().property(String.class);
76+
Project project = getProject();
77+
this.bootInfSpec = project.copySpec().into("BOOT-INF");
78+
this.mainClass = project.getObjects().property(String.class);
7779
configureBootInfSpec(this.bootInfSpec);
7880
getMainSpec().with(this.bootInfSpec);
79-
getProject().getConfigurations().all((configuration) -> {
81+
project.getConfigurations().all((configuration) -> {
8082
ResolvableDependencies incoming = configuration.getIncoming();
8183
incoming.afterResolve((resolvableDependencies) -> {
8284
if (resolvableDependencies == incoming) {
83-
this.resolvedDependencies.processConfiguration(configuration);
85+
this.resolvedDependencies.processConfiguration(project, configuration);
8486
}
8587
});
8688
});

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootWar.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,16 @@ public class BootWar extends War implements BootArchive {
7070
*/
7171
public BootWar() {
7272
this.support = new BootArchiveSupport(LAUNCHER, new LibrarySpec(), new ZipCompressionResolver());
73-
this.mainClass = getProject().getObjects().property(String.class);
73+
Project project = getProject();
74+
this.mainClass = project.getObjects().property(String.class);
7475
getWebInf().into("lib-provided", fromCallTo(this::getProvidedLibFiles));
7576
this.support.moveModuleInfoToRoot(getRootSpec());
7677
getRootSpec().eachFile(this.support::excludeNonZipLibraryFiles);
77-
getProject().getConfigurations().all((configuration) -> {
78+
project.getConfigurations().all((configuration) -> {
7879
ResolvableDependencies incoming = configuration.getIncoming();
7980
incoming.afterResolve((resolvableDependencies) -> {
8081
if (resolvableDependencies == incoming) {
81-
this.resolvedDependencies.processConfiguration(configuration);
82+
this.resolvedDependencies.processConfiguration(project, configuration);
8283
}
8384
});
8485
});

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/ResolvedDependencies.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,9 +22,9 @@
2222
import java.util.Set;
2323
import java.util.stream.Collectors;
2424

25+
import org.gradle.api.Project;
2526
import org.gradle.api.artifacts.Configuration;
2627
import org.gradle.api.artifacts.ModuleVersionIdentifier;
27-
import org.gradle.api.artifacts.ProjectDependency;
2828
import org.gradle.api.artifacts.ResolvedArtifact;
2929
import org.gradle.api.artifacts.ResolvedConfiguration;
3030

@@ -44,13 +44,15 @@ class ResolvedDependencies {
4444

4545
private final Map<Configuration, ResolvedConfigurationDependencies> configurationDependencies = new LinkedHashMap<>();
4646

47-
void processConfiguration(Configuration configuration) {
48-
Set<String> projectDependencyIds = configuration.getAllDependencies().withType(ProjectDependency.class).stream()
49-
.map((projectDependency) -> projectDependency.getGroup() + ":" + projectDependency.getName() + ":"
50-
+ projectDependency.getVersion())
47+
private String projectId(Project project) {
48+
return project.getGroup() + ":" + project.getName() + ":" + project.getVersion();
49+
}
50+
51+
void processConfiguration(Project project, Configuration configuration) {
52+
Set<String> localProjectIds = project.getRootProject().getAllprojects().stream().map(this::projectId)
5153
.collect(Collectors.toSet());
5254
this.configurationDependencies.put(configuration,
53-
new ResolvedConfigurationDependencies(projectDependencyIds, configuration.getResolvedConfiguration()));
55+
new ResolvedConfigurationDependencies(localProjectIds, configuration.getResolvedConfiguration()));
5456
}
5557

5658
DependencyDescriptor find(File file) {

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveIntegrationTests.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ void multiModuleImplicitLayers() throws IOException {
326326
assertThat(jarFile.getEntry(layerToolsJar)).isNotNull();
327327
assertThat(jarFile.getEntry(this.libPath + "alpha-1.2.3.jar")).isNotNull();
328328
assertThat(jarFile.getEntry(this.libPath + "bravo-1.2.3.jar")).isNotNull();
329+
assertThat(jarFile.getEntry(this.libPath + "charlie-1.2.3.jar")).isNotNull();
329330
assertThat(jarFile.getEntry(this.libPath + "commons-lang3-3.9.jar")).isNotNull();
330331
assertThat(jarFile.getEntry(this.libPath + "spring-core-5.2.5.RELEASE.jar")).isNotNull();
331332
assertThat(jarFile.getEntry(this.libPath + "spring-jcl-5.2.5.RELEASE.jar")).isNotNull();
@@ -347,8 +348,9 @@ void multiModuleImplicitLayers() throws IOException {
347348
assertThat(indexedLayers.get("dependencies")).containsExactlyElementsOf(expectedDependencies);
348349
assertThat(indexedLayers.get("spring-boot-loader")).containsExactly("org/");
349350
assertThat(indexedLayers.get("snapshot-dependencies")).containsExactlyElementsOf(expectedSnapshotDependencies);
350-
assertThat(indexedLayers.get("application")).containsExactly(getExpectedApplicationLayerContents(
351-
this.classesPath, this.libPath + "alpha-1.2.3.jar", this.libPath + "bravo-1.2.3.jar"));
351+
assertThat(indexedLayers.get("application"))
352+
.containsExactly(getExpectedApplicationLayerContents(this.classesPath, this.libPath + "alpha-1.2.3.jar",
353+
this.libPath + "bravo-1.2.3.jar", this.libPath + "charlie-1.2.3.jar"));
352354
BuildResult listLayers = this.gradleBuild.build("listLayers");
353355
assertThat(listLayers.task(":listLayers").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
354356
String listLayersOutput = listLayers.getOutput();
@@ -417,6 +419,7 @@ void multiModuleCustomLayers() throws IOException {
417419
assertThat(jarFile.getEntry(layerToolsJar)).isNotNull();
418420
assertThat(jarFile.getEntry(this.libPath + "alpha-1.2.3.jar")).isNotNull();
419421
assertThat(jarFile.getEntry(this.libPath + "bravo-1.2.3.jar")).isNotNull();
422+
assertThat(jarFile.getEntry(this.libPath + "charlie-1.2.3.jar")).isNotNull();
420423
assertThat(jarFile.getEntry(this.libPath + "commons-lang3-3.9.jar")).isNotNull();
421424
assertThat(jarFile.getEntry(this.libPath + "spring-core-5.2.5.RELEASE.jar")).isNotNull();
422425
assertThat(jarFile.getEntry(this.libPath + "spring-jcl-5.2.5.RELEASE.jar")).isNotNull();
@@ -432,6 +435,7 @@ void multiModuleCustomLayers() throws IOException {
432435
Set<String> expectedSubprojectDependencies = new TreeSet<>();
433436
expectedSubprojectDependencies.add(this.libPath + "alpha-1.2.3.jar");
434437
expectedSubprojectDependencies.add(this.libPath + "bravo-1.2.3.jar");
438+
expectedSubprojectDependencies.add(this.libPath + "charlie-1.2.3.jar");
435439
Set<String> expectedDependencies = new TreeSet<>();
436440
expectedDependencies.add(this.libPath + "spring-core-5.2.5.RELEASE.jar");
437441
expectedDependencies.add(this.libPath + "spring-jcl-5.2.5.RELEASE.jar");
@@ -492,7 +496,7 @@ private void createJar(File location, Consumer<Attributes> attributesConfigurer)
492496
private void writeSettingsGradle() {
493497
try (PrintWriter writer = new PrintWriter(
494498
new FileWriter(new File(this.gradleBuild.getProjectDir(), "settings.gradle")))) {
495-
writer.println("include 'alpha', 'bravo'");
499+
writer.println("include 'alpha', 'bravo', 'charlie'");
496500
}
497501
catch (IOException ex) {
498502
throw new RuntimeException(ex);

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void applyLayered(Action<LayeredSpec> action) {
116116

117117
@Override
118118
void populateResolvedDependencies(Configuration configuration) {
119-
getTask().getResolvedDependencies().processConfiguration(configuration);
119+
getTask().getResolvedDependencies().processConfiguration(getTask().getProject(), configuration);
120120
}
121121

122122
@Override

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootWarTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ protected void executeTask() {
116116

117117
@Override
118118
void populateResolvedDependencies(Configuration configuration) {
119-
getTask().getResolvedDependencies().processConfiguration(configuration);
119+
getTask().getResolvedDependencies().processConfiguration(getTask().getProject(), configuration);
120120
}
121121

122122
@Override

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-multiModuleCustomLayers.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ subprojects {
77
apply plugin: 'java'
88
group = 'org.example.projects'
99
version = '1.2.3'
10+
if (it.name == 'bravo') {
11+
dependencies {
12+
implementation(project(':charlie'))
13+
}
14+
}
1015
}
1116

1217
bootJar {

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-multiModuleImplicitLayers.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ subprojects {
77
apply plugin: 'java'
88
group = 'org.example.projects'
99
version = '1.2.3'
10+
if (it.name == 'bravo') {
11+
dependencies {
12+
implementation(project(':charlie'))
13+
}
14+
}
1015
}
1116

1217
bootJar {

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootWarIntegrationTests-multiModuleCustomLayers.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ subprojects {
88
apply plugin: 'java'
99
group = 'org.example.projects'
1010
version = '1.2.3'
11+
if (it.name == 'bravo') {
12+
dependencies {
13+
implementation(project(':charlie'))
14+
}
15+
}
1116
}
1217

1318
bootWar {

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootWarIntegrationTests-multiModuleImplicitLayers.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ subprojects {
88
apply plugin: 'java'
99
group = 'org.example.projects'
1010
version = '1.2.3'
11+
if (it.name == 'bravo') {
12+
dependencies {
13+
implementation(project(':charlie'))
14+
}
15+
}
1116
}
1217

1318
bootWar {

0 commit comments

Comments
 (0)