From 534078ab2e9a7d56bd4b04f19f95f1ea78d27efc Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Wed, 20 Dec 2023 19:12:59 +0100 Subject: [PATCH] Fix the plugin default groupId (#3842) The default groupId for Maven plugins is not the one from the current pom but `org.apache.maven.plugins`. Noticed while working on the update recipes for Quarkus 3.7. --- .../org/openrewrite/maven/MavenVisitor.java | 2 +- .../maven/UpgradePluginVersionTest.java | 50 ++++++++++++++++++- 2 files changed, 49 insertions(+), 3 deletions(-) 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 df99125fe87..4e87602cea8 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/MavenVisitor.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/MavenVisitor.java @@ -198,7 +198,7 @@ public boolean isPluginTag(String groupId, @Nullable String artifactId) { private boolean hasPluginGroupId(String groupId) { Xml.Tag tag = getCursor().getValue(); - boolean isGroupIdFound = matchesGlob(tag.getChildValue("groupId").orElse(getResolutionResult().getPom().getGroupId()), groupId); + boolean isGroupIdFound = matchesGlob(tag.getChildValue("groupId").orElse("org.apache.maven.plugins"), groupId); if (!isGroupIdFound && getResolutionResult().getPom().getProperties() != null) { if (tag.getChildValue("groupId").isPresent() && tag.getChildValue("groupId").get().trim().startsWith("${")) { String propertyKey = tag.getChildValue("groupId").get().trim(); diff --git a/rewrite-maven/src/test/java/org/openrewrite/maven/UpgradePluginVersionTest.java b/rewrite-maven/src/test/java/org/openrewrite/maven/UpgradePluginVersionTest.java index 589acd5ceef..73ec49861f8 100644 --- a/rewrite-maven/src/test/java/org/openrewrite/maven/UpgradePluginVersionTest.java +++ b/rewrite-maven/src/test/java/org/openrewrite/maven/UpgradePluginVersionTest.java @@ -244,12 +244,12 @@ void upgradeVersionIgnoringParent() { """ 4.0.0 - + pom org.openrewrite.example my-app-bom 1 - + @@ -668,4 +668,50 @@ void shouldAddVersionInOrder() { ) ); } + + @Test + void defaultPluginGroupId() { + rewriteRun( + spec -> spec.recipe(new UpgradePluginVersion( + "org.apache.maven.plugins", + "maven-compiler-plugin", + "3.11.0", + null, + null, + false + )), + pomXml( + """ + + com.mycompany.app + my-app + 1 + + + + maven-compiler-plugin + 3.10.0 + + + + + """, + """ + + com.mycompany.app + my-app + 1 + + + + maven-compiler-plugin + 3.11.0 + + + + + """ + ) + ); + } }