From 8a8d5ef1daf63cf1cd69e3100dfe70133839a578 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Tue, 27 Feb 2024 13:38:18 +0100 Subject: [PATCH] Fall back to default groupId when comparing plugins Fixes openrewrite/rewrite-maven-plugin#745 As per https://github.com/openrewrite/rewrite-maven-plugin/issues/745#issuecomment-1966447178 --- .../openrewrite/maven/RemoveRedundantDependencyVersions.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/RemoveRedundantDependencyVersions.java b/rewrite-maven/src/main/java/org/openrewrite/maven/RemoveRedundantDependencyVersions.java index 8dd4b98069a..911dbbaf2f6 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/RemoveRedundantDependencyVersions.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/RemoveRedundantDependencyVersions.java @@ -28,6 +28,7 @@ import java.util.List; import java.util.Objects; +import java.util.Optional; import static org.openrewrite.internal.StringUtils.matchesGlob; @@ -176,7 +177,9 @@ && matchesGlob(d.getArtifactId(), exceptedArtifactId)) { @Nullable private static String getManagedPluginVersion(ResolvedPom resolvedPom, @Nullable String groupId, String artifactId) { for (Plugin p : resolvedPom.getPluginManagement()) { - if (Objects.equals(p.getGroupId(), groupId) && + if (Objects.equals( + Optional.ofNullable(p.getGroupId()).orElse("org.apache.maven.plugins"), + Optional.ofNullable(groupId).orElse("org.apache.maven.plugins")) && Objects.equals(p.getArtifactId(), artifactId)) { return resolvedPom.getValue(p.getVersion()); }