From 659b30d9bb1e7dc515d960a472c8e93fed4444ed Mon Sep 17 00:00:00 2001 From: YiXuan Ding <1328032567@qq.com> Date: Fri, 15 Nov 2024 00:11:57 +0800 Subject: [PATCH 1/2] Remove deprecated getFiles() instead of getResolvedArtifacts() See gh-43191 --- .../boot/build/bom/CheckBom.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/CheckBom.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/CheckBom.java index 20e52fd3305..2651c4f5f4f 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/CheckBom.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/CheckBom.java @@ -32,6 +32,7 @@ import org.apache.maven.artifact.versioning.VersionRange; import org.gradle.api.DefaultTask; import org.gradle.api.GradleException; import org.gradle.api.artifacts.ConfigurationContainer; +import org.gradle.api.artifacts.ResolvedArtifact; import org.gradle.api.artifacts.dsl.DependencyHandler; import org.gradle.api.tasks.TaskAction; @@ -46,6 +47,7 @@ import org.springframework.boot.build.bom.bomr.version.DependencyVersion; * Checks the validity of a bom. * * @author Andy Wilkinson + * @author Wick Dynex */ public abstract class CheckBom extends DefaultTask { @@ -209,14 +211,17 @@ public abstract class CheckBom extends DefaultTask { private File resolveBom(Library library, String alignsWithBom) { String coordinates = alignsWithBom + ":" + library.getVersion().getVersion() + "@pom"; - Set files = this.configurations.detachedConfiguration(this.dependencies.create(coordinates)) - .getResolvedConfiguration() - .getFiles(); - if (files.size() != 1) { - throw new IllegalStateException( - "Expected a single file but '" + coordinates + "' resolved to " + files.size()); - } - return files.iterator().next(); - } + Set artifacts = this.configurations + .detachedConfiguration(this.dependencies.create(coordinates)) + .getResolvedConfiguration() + .getResolvedArtifacts(); + + if (artifacts.size() != 1) { + throw new IllegalStateException( + "Expected a single file but '" + coordinates + "' resolved to " + artifacts.size()); + } + + return artifacts.iterator().next().getFile(); + } } From df35d44ea7dee89b28aaf239b36781fafbf89cc0 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Tue, 19 Nov 2024 11:12:52 +0100 Subject: [PATCH 2/2] Polish "Remove deprecated getFiles() instead of getResolvedArtifacts()" See gh-43191 --- .../springframework/boot/build/bom/CheckBom.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/CheckBom.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/CheckBom.java index 2651c4f5f4f..250aa5d559e 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/CheckBom.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/CheckBom.java @@ -211,17 +211,15 @@ public abstract class CheckBom extends DefaultTask { private File resolveBom(Library library, String alignsWithBom) { String coordinates = alignsWithBom + ":" + library.getVersion().getVersion() + "@pom"; - Set artifacts = this.configurations - .detachedConfiguration(this.dependencies.create(coordinates)) - .getResolvedConfiguration() - .getResolvedArtifacts(); - + .detachedConfiguration(this.dependencies.create(coordinates)) + .getResolvedConfiguration() + .getResolvedArtifacts(); if (artifacts.size() != 1) { - throw new IllegalStateException( - "Expected a single file but '" + coordinates + "' resolved to " + artifacts.size()); + throw new IllegalStateException("Expected a single file but '%s' resolved to %d artifacts" + .formatted(coordinates, artifacts.size())); } - return artifacts.iterator().next().getFile(); } + }