diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/MavenVisitor.java b/rewrite-maven/src/main/java/org/openrewrite/maven/MavenVisitor.java
index a6d658cd9ed..559586b65b1 100644
--- a/rewrite-maven/src/main/java/org/openrewrite/maven/MavenVisitor.java
+++ b/rewrite-maven/src/main/java/org/openrewrite/maven/MavenVisitor.java
@@ -31,6 +31,7 @@
import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static org.openrewrite.internal.StringUtils.matchesGlob;
+import static org.openrewrite.maven.tree.Plugin.PLUGIN_DEFAULT_GROUPID;
public class MavenVisitor
extends XmlVisitor
{
@@ -403,7 +404,7 @@ public boolean isDependencyLikeTag() {
for (Plugin resolvedPlugin : plugins) {
String reqGroup = resolvedPlugin.getGroupId();
String reqVersion = resolvedPlugin.getVersion();
- if ((reqGroup == null || reqGroup.equals(tag.getChildValue("groupId").orElse(null))) &&
+ if (reqGroup.equals(tag.getChildValue("groupId").orElse(PLUGIN_DEFAULT_GROUPID)) &&
resolvedPlugin.getArtifactId().equals(tag.getChildValue("artifactId").orElse(null)) &&
(reqVersion == null || reqVersion.equals(tag.getChildValue("version").orElse(null)))) {
return resolvedPlugin;
diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/internal/RawPom.java b/rewrite-maven/src/main/java/org/openrewrite/maven/internal/RawPom.java
index 2468380c964..ddd8a2c5730 100755
--- a/rewrite-maven/src/main/java/org/openrewrite/maven/internal/RawPom.java
+++ b/rewrite-maven/src/main/java/org/openrewrite/maven/internal/RawPom.java
@@ -40,6 +40,7 @@
import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
+import static org.openrewrite.maven.tree.Plugin.PLUGIN_DEFAULT_GROUPID;
/**
* A value object deserialized directly from POM XML
@@ -249,6 +250,7 @@ public static class PluginManagement {
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@Data
public static class Plugin {
+ @Nullable
String groupId;
String artifactId;
@@ -510,9 +512,9 @@ private List mapPlugins(@Nullable List(rawPlugins.size());
for (Plugin rawPlugin : rawPlugins) {
-
+ String pluginGroupId = rawPlugin.getGroupId();
plugins.add(new org.openrewrite.maven.tree.Plugin(
- rawPlugin.getGroupId(),
+ pluginGroupId == null ? PLUGIN_DEFAULT_GROUPID : pluginGroupId,
rawPlugin.getArtifactId(),
rawPlugin.getVersion(),
rawPlugin.getExtensions(),
diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/tree/Plugin.java b/rewrite-maven/src/main/java/org/openrewrite/maven/tree/Plugin.java
index 0c9edde7db3..6da00f313cb 100644
--- a/rewrite-maven/src/main/java/org/openrewrite/maven/tree/Plugin.java
+++ b/rewrite-maven/src/main/java/org/openrewrite/maven/tree/Plugin.java
@@ -30,6 +30,8 @@
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@Value
public class Plugin {
+ // default value as per https://maven.apache.org/xsd/maven-4.0.0.xsd
+ public static final String PLUGIN_DEFAULT_GROUPID = "org.apache.maven.plugins";
String groupId;
String artifactId;
diff --git a/rewrite-maven/src/test/java/org/openrewrite/maven/RemoveRedundantDependencyVersionsTest.java b/rewrite-maven/src/test/java/org/openrewrite/maven/RemoveRedundantDependencyVersionsTest.java
index 073d136b347..0ff8f2729ef 100644
--- a/rewrite-maven/src/test/java/org/openrewrite/maven/RemoveRedundantDependencyVersionsTest.java
+++ b/rewrite-maven/src/test/java/org/openrewrite/maven/RemoveRedundantDependencyVersionsTest.java
@@ -22,6 +22,7 @@
import org.openrewrite.Issue;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;
+import org.openrewrite.test.SourceSpec;
import java.util.Collections;
@@ -1290,6 +1291,170 @@ void removeRedundantVersionsFromPluginsManagedByParent() {
);
}
+ @Test
+ void removeRedundantVersionsFromPluginsManagedByParentNotSpecifyingGroupId() {
+ rewriteRun(
+ spec -> spec.recipe(new RemoveRedundantDependencyVersions(null, null, RemoveRedundantDependencyVersions.Comparator.GTE, null)),
+ pomXml(
+ """
+
+ 4.0.0
+ org.sample
+ parent
+ 1.0.0
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.7.18
+
+
+
+
+
+
+ maven-resources-plugin
+
+
+
+
+
+
+ """, SourceSpec::skip),
+ mavenProject("child", pomXml(
+ """
+
+ 4.0.0
+
+ org.sample
+ parent
+ 1.0.0
+
+
+ sample
+
+
+
+ maven-resources-plugin
+ 3.0.0
+
+
+
+
+
+
+
+ """,
+ """
+
+ 4.0.0
+
+ org.sample
+ parent
+ 1.0.0
+
+
+ sample
+
+
+
+ maven-resources-plugin
+
+
+
+
+
+
+
+ """
+ )
+ )
+ );
+ }
+
+ @Test
+ void removeRedundantDmVersionsFromPluginsManagedByParentNotSpecifyingGroupId() {
+ rewriteRun(
+ spec -> spec.recipe(new RemoveRedundantDependencyVersions(null, null, RemoveRedundantDependencyVersions.Comparator.GTE, null)),
+ pomXml(
+ """
+
+ 4.0.0
+ org.sample
+ parent
+ 1.0.0
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.7.18
+
+
+
+
+
+
+ maven-resources-plugin
+
+
+
+
+
+
+ """, SourceSpec::skip),
+ mavenProject("child", pomXml(
+ """
+
+ 4.0.0
+
+ org.sample
+ parent
+ 1.0.0
+
+
+ sample
+
+
+
+
+ maven-resources-plugin
+ 3.0.0
+
+
+
+
+
+
+
+
+ """,
+ """
+
+ 4.0.0
+
+ org.sample
+ parent
+ 1.0.0
+
+
+ sample
+
+
+
+
+ maven-resources-plugin
+
+
+
+
+
+
+
+
+ """
+ )
+ )
+ );
+ }
+
@Test
void keepPluginIfParentInheritanceDisabled() {
rewriteRun(