Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming groupId in maven

Tags:

I'm in a middle of a refactoring and house keeping process of a multi-module Maven3 project and I need to rename groupId and artifactId of some artifacts.

Is there a way to rename both groupId and artifactId?
I know I can use some find-and-replace tool like sed, but I'm wondering if there's a mojo like versions-maven-plugin (e.g.: mvn versions:set -DnewVersion=1.0.3-SNAPSHOT) but for groupId and artifactId.

like image 933
joao cenoura Avatar asked Nov 06 '13 15:11

joao cenoura


People also ask

How do I rename a Maven project?

To rename the project, simply right-click the project and select "Refactor/Rename...". Fill in the new name and click OK.

What does groupId mean in Maven?

groupId uniquely identifies your project across all projects. A group ID should follow Java's package name rules. This means it starts with a reversed domain name you control. For example, org.apache.maven , org.apache.commons.


1 Answers

Is there a way to rename both groupId and artifactId?

As of today, the answer to your question is simple:

  • No, there is no such plugin for renaming.

Write your own Maven Plugin

I guess you might be able to write such a maven plugin, though.

You can include this field in your Mojo:

    @Parameter(defaultValue = "${project}", readonly = true)     @SuppressWarnings("UnusedDeclaration")     private MavenProject project; 

The MavenProject class has the methods you are looking for (setArtifactId, etc.).

In fact, the SetMojo from the maven-version-plugin will do exactly this for you.


This answer will be updated as soon as there is such a plugin.

like image 180
Benjamin Marwell Avatar answered Sep 21 '22 03:09

Benjamin Marwell