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.
To rename the project, simply right-click the project and select "Refactor/Rename...". Fill in the new name and click OK.
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.
Is there a way to rename both groupId and artifactId?
As of today, the answer to your question is simple:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With