Skip to content

Commit 534078a

Browse files
authored
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.
1 parent dd39b24 commit 534078a

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

rewrite-maven/src/main/java/org/openrewrite/maven/MavenVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public boolean isPluginTag(String groupId, @Nullable String artifactId) {
198198

199199
private boolean hasPluginGroupId(String groupId) {
200200
Xml.Tag tag = getCursor().getValue();
201-
boolean isGroupIdFound = matchesGlob(tag.getChildValue("groupId").orElse(getResolutionResult().getPom().getGroupId()), groupId);
201+
boolean isGroupIdFound = matchesGlob(tag.getChildValue("groupId").orElse("org.apache.maven.plugins"), groupId);
202202
if (!isGroupIdFound && getResolutionResult().getPom().getProperties() != null) {
203203
if (tag.getChildValue("groupId").isPresent() && tag.getChildValue("groupId").get().trim().startsWith("${")) {
204204
String propertyKey = tag.getChildValue("groupId").get().trim();

rewrite-maven/src/test/java/org/openrewrite/maven/UpgradePluginVersionTest.java

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,12 @@ void upgradeVersionIgnoringParent() {
244244
"""
245245
<project>
246246
<modelVersion>4.0.0</modelVersion>
247-
247+
248248
<packaging>pom</packaging>
249249
<groupId>org.openrewrite.example</groupId>
250250
<artifactId>my-app-bom</artifactId>
251251
<version>1</version>
252-
252+
253253
<build>
254254
<pluginManagement>
255255
<plugins>
@@ -668,4 +668,50 @@ void shouldAddVersionInOrder() {
668668
)
669669
);
670670
}
671+
672+
@Test
673+
void defaultPluginGroupId() {
674+
rewriteRun(
675+
spec -> spec.recipe(new UpgradePluginVersion(
676+
"org.apache.maven.plugins",
677+
"maven-compiler-plugin",
678+
"3.11.0",
679+
null,
680+
null,
681+
false
682+
)),
683+
pomXml(
684+
"""
685+
<project>
686+
<groupId>com.mycompany.app</groupId>
687+
<artifactId>my-app</artifactId>
688+
<version>1</version>
689+
<build>
690+
<plugins>
691+
<plugin>
692+
<artifactId>maven-compiler-plugin</artifactId>
693+
<version>3.10.0</version>
694+
</plugin>
695+
</plugins>
696+
</build>
697+
</project>
698+
""",
699+
"""
700+
<project>
701+
<groupId>com.mycompany.app</groupId>
702+
<artifactId>my-app</artifactId>
703+
<version>1</version>
704+
<build>
705+
<plugins>
706+
<plugin>
707+
<artifactId>maven-compiler-plugin</artifactId>
708+
<version>3.11.0</version>
709+
</plugin>
710+
</plugins>
711+
</build>
712+
</project>
713+
"""
714+
)
715+
);
716+
}
671717
}

0 commit comments

Comments
 (0)