From 47969ec7c94f97cedc836210f494e6cf67ddbce3 Mon Sep 17 00:00:00 2001 From: Marcus Hert Da Coregio Date: Mon, 30 Oct 2023 08:28:15 -0300 Subject: [PATCH] Fix verifyDependenciesVersions not working with s101 Issue gh-14047 --- .../VerifyDependenciesVersionsPlugin.java | 35 ++++++++----------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/buildSrc/src/main/java/org/springframework/security/convention/versions/VerifyDependenciesVersionsPlugin.java b/buildSrc/src/main/java/org/springframework/security/convention/versions/VerifyDependenciesVersionsPlugin.java index d22ac3f456..248031c359 100644 --- a/buildSrc/src/main/java/org/springframework/security/convention/versions/VerifyDependenciesVersionsPlugin.java +++ b/buildSrc/src/main/java/org/springframework/security/convention/versions/VerifyDependenciesVersionsPlugin.java @@ -17,10 +17,8 @@ package org.springframework.security.convention.versions; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.stream.Collectors; import org.gradle.api.DefaultTask; @@ -39,31 +37,22 @@ public class VerifyDependenciesVersionsPlugin implements Plugin { TaskProvider verifyDependenciesVersionsTaskProvider = project.getTasks().register("verifyDependenciesVersions", VerifyDependenciesVersionsTask.class, (task) -> { task.setGroup("Verification"); task.setDescription("Verify that specific dependencies are using the same version"); - List allConfigurations = new ArrayList<>(); - allConfigurations.addAll(getConfigurations(project)); - allConfigurations.addAll(getSubprojectsConfigurations(project.getSubprojects())); + List allConfigurations = new ArrayList<>(getConfigurations(project)); task.setConfigurations(allConfigurations); }); project.getTasks().named(JavaBasePlugin.CHECK_TASK_NAME, checkTask -> checkTask.dependsOn(verifyDependenciesVersionsTaskProvider)); } - private List getConfigurations(Project project) { - return project.getConfigurations().stream() - .filter(Configuration::isCanBeResolved) - .filter((config) -> config.getName().equals("runtimeClasspath")) - .collect(Collectors.toList()); - } - - private List getSubprojectsConfigurations(Set subprojects) { - if (subprojects.isEmpty()) { - return Collections.emptyList(); + private List getConfigurations(Project rootProject) { + List configurations = new ArrayList<>(); + for (Project project : rootProject.getAllprojects()) { + List runtimeClasspath = project.getConfigurations().stream() + .filter(Configuration::isCanBeResolved) + .filter((config) -> config.getName().equals("runtimeClasspath")) + .collect(Collectors.toList()); + configurations.addAll(runtimeClasspath); } - List subprojectConfigurations = new ArrayList<>(); - for (Project subproject : subprojects) { - subprojectConfigurations.addAll(getConfigurations(subproject)); - subprojectConfigurations.addAll(getSubprojectsConfigurations(subproject.getSubprojects())); - } - return subprojectConfigurations; + return configurations; } public static class VerifyDependenciesVersionsTask extends DefaultTask { @@ -79,6 +68,10 @@ public class VerifyDependenciesVersionsPlugin implements Plugin { Map> artifacts = getDependencies(this.configurations); List oauth2OidcSdk = artifacts.get("oauth2-oidc-sdk"); List nimbusJoseJwt = artifacts.get("nimbus-jose-jwt"); + if (oauth2OidcSdk == null) { + // Could not resolve oauth2-oidc-sdk + return; + } if (oauth2OidcSdk.size() > 1) { throw new IllegalStateException("Found multiple versions of oauth2-oidc-sdk: " + oauth2OidcSdk); }