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, which may be given as an exact version or as a node-style semver selector resolved against the new plugin's available versions.

Recipe source

GitHub: ChangePluginGroupIdAndArtifactId.java, Issue Tracker, Code Genome Project

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 or node-style semver selector used to select the version number. You can also use latest.release for the latest available version and latest.patch if the current version is a valid semantic version. For more details, you can look at the documentation page of version selectors29.X

Used by

This recipe is used as part of the following composite recipes:

Example

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>

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

This recipe has no required configuration parameters and comes from a rewrite core library. It can be activated directly without adding any dependencies.

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

OpenRewrite artifacts, including the Maven and Gradle plugins themselves, are distributed through the Code Genome Project repository (https://artifacts.codegenomeproject.org/maven), which requires authentication. Sign in to the Code Genome Project to create a download token; your build authenticates with the email or username you signed in with, plus that token as the password. See the quickstart guide for details.

  1. Add the Code Genome Project credentials to your Maven settings.xml file (typically at ~/.m2/settings.xml), replacing USERNAME and TOKEN with your own:
    settings.xml
    <settings>
    <servers>
    <server>
    <id>codegenome</id>
    <username>USERNAME</username>
    <password>TOKEN</password>
    </server>
    </servers>
    </settings>
  2. Add the following to your pom.xml file:
    pom.xml
    <project>
    <repositories>
    <repository>
    <id>codegenome</id>
    <url>https://artifacts.codegenomeproject.org/maven</url>
    </repository>
    </repositories>
    <pluginRepositories>
    <pluginRepository>
    <id>codegenome</id>
    <url>https://artifacts.codegenomeproject.org/maven</url>
    </pluginRepository>
    </pluginRepositories>
    <build>
    <plugins>
    <plugin>
    <groupId>org.openrewrite.maven</groupId>
    <artifactId>rewrite-maven-plugin</artifactId>
    <version>6.47.0</version>
    <configuration>
    <exportDatatables>true</exportDatatables>
    <activeRecipes>
    <recipe>com.yourorg.ChangePluginGroupIdAndArtifactIdExample</recipe>
    </activeRecipes>
    </configuration>
    </plugin>
    </plugins>
    </build>
    </project>
  3. 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.