Skip to content

Commit 409e3cc

Browse files
committed
Ignore resolution of copied configuration
When a Configuration is copied, any before and after resolve actions that are registered with its ResolvableDependencies are also copied over. This means that, when a copied configuration is resolved the resolution actions may be called on a ResolvableDependencies instances that isn't the one to which they were added. Previously, the above-described Gradle behaviour would result in BootJar accessed the ResolvedConfiguration of a Configuration that may not have yet been resolved. At best this would trigger Configuration resolution and at worst it would fail. A failure could occur if the configuration had been copied so that it could be made resolvable. The afterResolve action would then try to access the ResolvedConfiguration of the original Configuration. This would trigger a resolution attempt that fails due to the original configuration being marked as unresolvable. This commit updates the afterResolve action in BootJar to check that the ResolvableDependencies with which it is called matches the ResolvableDependencies with which it was original registered. Only when the two match, and therefore the configuration has actually been resolved, does processing proceed. Fixes gh-24072
1 parent e2af680 commit 409e3cc

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
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: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,11 @@ public BootJar() {
8080
getMainSpec().with(this.bootInfSpec);
8181
getProject().getConfigurations().all((configuration) -> {
8282
ResolvableDependencies incoming = configuration.getIncoming();
83-
incoming.afterResolve(
84-
(resolvableDependencies) -> this.resolvedDependencies.processConfiguration(configuration));
83+
incoming.afterResolve((resolvableDependencies) -> {
84+
if (resolvableDependencies == incoming) {
85+
this.resolvedDependencies.processConfiguration(configuration);
86+
}
87+
});
8588
});
8689
}
8790

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,13 @@ void multiModuleCustomLayers() throws IOException {
289289
assertExtractedLayers(layerNames, indexedLayers);
290290
}
291291

292+
@TestTemplate
293+
void whenAResolvableCopyOfAnUnresolvableConfigurationIsResolvedThenResolutionSucceeds() {
294+
BuildResult build = this.gradleBuild.build("resolveResolvableCopyOfUnresolvableConfiguration");
295+
assertThat(build.task(":resolveResolvableCopyOfUnresolvableConfiguration").getOutcome())
296+
.isEqualTo(TaskOutcome.SUCCESS);
297+
}
298+
292299
private void assertExtractedLayers(List<String> layerNames, Map<String, List<String>> indexedLayers)
293300
throws IOException {
294301
Map<String, List<String>> extractedLayers = readExtractedLayers(this.gradleBuild.getProjectDir(), layerNames);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
plugins {
2+
id 'java'
3+
id 'org.springframework.boot' version '{version}'
4+
}
5+
6+
bootJar {
7+
mainClass = 'com.example.Application'
8+
}
9+
10+
task resolveResolvableCopyOfUnresolvableConfiguration {
11+
doFirst {
12+
def copy = configurations.implementation.copyRecursive()
13+
copy.canBeResolved = true
14+
copy.resolve()
15+
}
16+
}

0 commit comments

Comments
 (0)