How to rename maven pom artifactId using IntelliJ refactoring?
intellij-idea, java, maven
Solution
`Replace in Path` (Ctrl+Shift+R by default) action with text to find `<artifactId>OLD-ARTIFACT-ID</artifactId>` and text to replace `<artifactId>NEW-ARTIFACT-ID</artifactId>` will do most of the work automatically with the minimum amount of false positives, especially if you additionally configure the proper file name filter (`pom.xml`, obviously).
In detail, here is the complete sequence of steps to rename the maven-based module (assuming that the name of the module matches the name of the directory where the module is located):
- Comment out the relevant `<module>OLD-ARTIFACT-ID</module>` lines in parent/aggregator poms, then allow IDEA to re-import the project and allow it to remove excluded modules from the project. It is better to remove leftover .iml files too.
- Perform search&replace from `<artifactId>OLD-ARTIFACT-ID</artifactId>` to `<artifactId>NEW-ARTIFACT-ID</artifactId>` to rename the module in question and to fix all dependency references to it.
- Perform search&replace from `<module>OLD-ARTIFACT-ID</module>` to `<module>NEW-ARTIFACT-ID</module>` to fix all aggregation references to it.
- Rename the module directory.
- Uncomment the relevant `<module>NEW-ARTIFACT-ID</module>` lines in parent/aggregator POM files, then allow IDEA to re-import the project.
If you feel like IDEA misses some useful functionality you should create a feature request at http://youtrack.jetbrains.com/. In this particular case, vote for IDEA-94223, IDEA-72181 and IDEA-104344.
Problem
I am using IntelliJ 13 and have a Java project setup with its modules based on maven projects. There is a maven project that I must rename, so I will have to change it's artifactId property value in the pom file. If I do this manually, I will then have to find all its occurrences and modify those manually as well (ex: where it is included as a module and where it is used as a dependency). Since IntelliJ provides many refactoring techniques, I thought refactor->rename on the pom artifactId property would be supported, however it does not seem to be. I could try and do a find/replace .. but that still makes me do all the work logic (error-prone). IMO, IntelliJ should be able to detect where the pom is included as a module and which other modules use it as a dependency - anyone know of an automatic way to do this - or am I missing something here?