Java 如何使用 IntelliJ 重构重命名 maven pom artifactId?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23757048/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to rename maven pom artifactId using IntelliJ refactoring?
提问by Morgan Kobeissi
I am using IntelliJ 13 and have a Java project setup with its modules based on maven projects.
我正在使用 IntelliJ 13 并且有一个 Java 项目设置,其模块基于 maven 项目。
There is a maven project that I must rename, so I will have to change it's artifactId property value in the pom file.
有一个 maven 项目我必须重命名,所以我必须在 pom 文件中更改它的 artifactId 属性值。
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.
由于 IntelliJ 提供了许多重构技术,我认为 pom artifactId 属性上的 refactor->rename 将被支持,但它似乎不是。
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?
IMO,IntelliJ 应该能够检测到 pom 作为模块包含在何处以及哪些其他模块将其用作依赖项 - 任何人都知道自动执行此操作的方法 - 或者我在这里遗漏了什么?
采纳答案by Oleg Estekhin
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).
Replace in Path
(默认情况下为 Ctrl+Shift+R)带有要查找的<artifactId>OLD-ARTIFACT-ID</artifactId>
文本和要替换的文本的操作<artifactId>NEW-ARTIFACT-ID</artifactId>
将自动完成大部分工作,并且误报最少,特别是如果您另外配置了正确的文件名过滤器(pom.xml
显然)。
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):
详细来说,这里是重命名基于 maven 的模块的完整步骤序列(假设模块的名称与模块所在的目录的名称匹配):
- 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.
- 注释掉
<module>OLD-ARTIFACT-ID</module>
parent/aggregator poms 中的相关行,然后允许 IDEA 重新导入项目并允许它从项目中删除排除的模块。最好也删除剩余的 .iml 文件。 - 执行 search&replace from
<artifactId>OLD-ARTIFACT-ID</artifactId>
to<artifactId>NEW-ARTIFACT-ID</artifactId>
重命名有问题的模块并修复对它的所有依赖项引用。 - 从
<module>OLD-ARTIFACT-ID</module>
到执行搜索和替换<module>NEW-ARTIFACT-ID</module>
以修复对它的所有聚合引用。 - 重命名模块目录。
- 取消注释
<module>NEW-ARTIFACT-ID</module>
父/聚合器 POM 文件中的相关行,然后允许 IDEA 重新导入项目。
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-72181and IDEA-104344.
如果您觉得 IDEA 遗漏了一些有用的功能,您应该在http://youtrack.jetbrains.com/创建一个功能请求。在这种特殊情况下,请投票给IDEA-94223、IDEA-72181和IDEA- 104344。