From da8dafe1381272c3c7d657b250a40e7b74c966c7 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 30 May 2022 18:01:55 +0100 Subject: [PATCH] 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 --- .../boot/gradle/tasks/bundling/ResolvedDependencies.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 fc7bdb89db..b4644094b0 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-2021 the original author or authors. + * Copyright 2012-2022 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. @@ -24,6 +24,7 @@ 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; @@ -75,7 +76,11 @@ class ResolvedDependencies { ResolvedConfigurationDependencies(Set projectDependencyIds, ResolvedConfiguration resolvedConfiguration) { if (!resolvedConfiguration.hasError()) { - for (ResolvedArtifact resolvedArtifact : resolvedConfiguration.getResolvedArtifacts()) { + 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());