Skip to content

Commit da8dafe

Browse files
committed
Make afterResolve hook used by bootJar and bootWar more robust
Previously, ResolvedDependencies used hasError on ResolvedConfiguration to check that it was safe to work with all of the resolved configuration's artifacts and their files. This check is not sufficient as errors can still occur later on. This commit updates ResolvedDependencies to use a lenient configuration, thereby avoiding any problems that may be caused by errors that occur after the hasError check. Closes gh-30586
1 parent 419ac26 commit da8dafe

File tree

1 file changed

+7
-2
lines changed
  • spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling

1 file changed

+7
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 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.
@@ -24,6 +24,7 @@
2424

2525
import org.gradle.api.Project;
2626
import org.gradle.api.artifacts.Configuration;
27+
import org.gradle.api.artifacts.LenientConfiguration;
2728
import org.gradle.api.artifacts.ModuleVersionIdentifier;
2829
import org.gradle.api.artifacts.ResolvedArtifact;
2930
import org.gradle.api.artifacts.ResolvedConfiguration;
@@ -75,7 +76,11 @@ private static class ResolvedConfigurationDependencies {
7576
ResolvedConfigurationDependencies(Set<String> projectDependencyIds,
7677
ResolvedConfiguration resolvedConfiguration) {
7778
if (!resolvedConfiguration.hasError()) {
78-
for (ResolvedArtifact resolvedArtifact : resolvedConfiguration.getResolvedArtifacts()) {
79+
LenientConfiguration lenientConfiguration = resolvedConfiguration.getLenientConfiguration();
80+
// Ensure that all files are resolved, allowing Gradle to resolve in
81+
// parallel if they are not
82+
lenientConfiguration.getFiles();
83+
for (ResolvedArtifact resolvedArtifact : lenientConfiguration.getArtifacts()) {
7984
ModuleVersionIdentifier id = resolvedArtifact.getModuleVersion().getId();
8085
boolean projectDependency = projectDependencyIds
8186
.contains(id.getGroup() + ":" + id.getName() + ":" + id.getVersion());

0 commit comments

Comments
 (0)