Skip to content

Commit

Permalink
Fix the plugin default groupId
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gsmet committed Dec 20, 2023
1 parent dd39b24 commit 195b34f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,12 @@ void upgradeVersionIgnoringParent() {
"""
<project>
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<groupId>org.openrewrite.example</groupId>
<artifactId>my-app-bom</artifactId>
<version>1</version>
<build>
<pluginManagement>
<plugins>
Expand Down Expand Up @@ -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(
"""
<project>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.0</version>
</plugin>
</plugins>
</build>
</project>
""",
"""
<project>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
</plugin>
</plugins>
</build>
</project>
"""
)
);
}
}

0 comments on commit 195b34f

Please sign in to comment.