Skip to main content

Change Maven plugin group and artifact ID

org.openrewrite.maven.ChangePluginGroupIdAndArtifactId

Change the groupId and/or the artifactId of a specified Maven plugin. Optionally update the plugin version. This recipe does not perform any validation and assumes all values passed are valid.

Recipe source

GitHub, Issue Tracker, Maven Central

This recipe is available under the Apache License Version 2.0.

Options

TypeNameDescriptionExample
StringoldGroupIdThe old group ID to replace. The group ID is the first part of a plugin coordinate 'com.google.guava:guava:VERSION'. Supports glob expressions.org.openrewrite.recipe
StringoldArtifactIdThe old artifactId to replace. The artifact ID is the second part of a plugin coordinate 'com.google.guava:guava:VERSION'. Supports glob expressions.my-deprecated-maven-plugin
StringnewGroupIdOptional. The new group ID to use.corp.internal.openrewrite.recipe
StringnewArtifactIdOptional. The new artifact ID to use.my-new-maven-plugin
StringnewVersionOptional. An exact version number.29.X

Examples

Example 1
Parameters
ParameterValue
oldGroupIdio.quarkus
oldArtifactIdquarkus-bootstrap-maven-plugin
newGroupIdnull
newArtifactIdquarkus-extension-maven-plugin
newVersionnull
Before
pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bootstrap-maven-plugin</artifactId>
<version>3.0.0.Beta1</version>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>profile</id>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bootstrap-maven-plugin</artifactId>
<version>3.0.0.Beta1</version>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
After
pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-maven-plugin</artifactId>
<version>3.0.0.Beta1</version>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>profile</id>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-maven-plugin</artifactId>
<version>3.0.0.Beta1</version>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

Example 2
Parameters
ParameterValue
oldGroupIdio.quarkus
oldArtifactIdquarkus-bootstrap-maven-plugin
newGroupIdnull
newArtifactIdquarkus-extension-maven-plugin
newVersion4.0.0
Before
pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bootstrap-maven-plugin</artifactId>
<version>3.0.0.Beta1</version>
</plugin>
</plugins>
</build>
</project>
After
pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-maven-plugin</artifactId>
<version>4.0.0</version>
</plugin>
</plugins>
</build>
</project>

Usage

This recipe has required configuration parameters. Recipes with required configuration parameters cannot be activated directly (unless you are running them via the Moderne CLI). To activate this recipe you must create a new recipe which fills in the required parameters. In your rewrite.yml create a new recipe with a unique name. For example: com.yourorg.ChangePluginGroupIdAndArtifactIdExample. Here's how you can define and customize such a recipe within your rewrite.yml:

rewrite.yml
---
type: specs.openrewrite.org/v1beta/recipe
name: com.yourorg.ChangePluginGroupIdAndArtifactIdExample
displayName: Change Maven plugin group and artifact ID example
recipeList:
- org.openrewrite.maven.ChangePluginGroupIdAndArtifactId:
oldGroupId: org.openrewrite.recipe
oldArtifactId: my-deprecated-maven-plugin
newGroupId: corp.internal.openrewrite.recipe
newArtifactId: my-new-maven-plugin
newVersion: 29.X

Now that com.yourorg.ChangePluginGroupIdAndArtifactIdExample has been defined, activate it in your build file:

  1. Add the following to your pom.xml file:
pom.xml
<project>
<build>
<plugins>
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>6.7.0</version>
<configuration>
<exportDatatables>true</exportDatatables>
<activeRecipes>
<recipe>com.yourorg.ChangePluginGroupIdAndArtifactIdExample</recipe>
</activeRecipes>
</configuration>
</plugin>
</plugins>
</build>
</project>
  1. Run mvn rewrite:run to run the recipe.

See how this recipe works across multiple open-source repositories

Run this recipe on OSS repos at scale with the Moderne SaaS.

The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories.

Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.

Data Tables

Maven metadata failures

org.openrewrite.maven.table.MavenMetadataFailures

Attempts to resolve maven metadata that failed.

Column NameDescription
Group idThe groupId of the artifact for which the metadata download failed.
Artifact idThe artifactId of the artifact for which the metadata download failed.
VersionThe version of the artifact for which the metadata download failed.
Maven repositoryThe URL of the Maven repository that the metadata download failed on.
SnapshotsDoes the repository support snapshots.
ReleasesDoes the repository support releases.
FailureThe reason the metadata download failed.

Contributors

George Gastaldi, Jonathan Schnéider, JesseEstum, Guillaume Smet, Laurens Westerlaken, Kevin Carpenter™️, Tim te Beek