Java 如何从 Intellij Maven 项目中永久删除模块?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19568134/
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 remove Modules from a Intellij Maven Project permanently?
提问by herpnderpn
I am currently working on a larger scale Maven-based project in IntelliJIdea 12.1.6 Ultimate. I have been working with IntelliJIdea since about 5 months.
我目前正在 IntelliJIdea 12.1.6 Ultimate 中从事更大规模的基于 Maven 的项目。大约 5 个月以来,我一直在使用 IntelliJIdea。
An included module has dependencies on another module. The dependent module's source was also part of my project until recently. Since I removed the dependent module from my project, I get compile errors whenever I am trying to compile the source without maven.
包含的模块依赖于另一个模块。直到最近,依赖模块的源也是我项目的一部分。由于我从项目中删除了依赖模块,因此每当我尝试在没有 maven 的情况下编译源代码时,都会出现编译错误。
The pom.xml of removed modules in Intellij seem to be placed onto the Settings->Maven->Ignored Files. I cant seem to remove it from there, only check or uncheck it. It's not possible to include the module again since IntelliJ will say its still under Ignored Files.
Intellij 中删除模块的 pom.xml 似乎被放置在 Settings->Maven->Ignored Files 上。我似乎无法从那里删除它,只能选中或取消选中它。不可能再次包含该模块,因为 IntelliJ 会说它仍然在 Ignored Files 下。
2 ways allow me to compile again: Uncheck the pom from Ignored files, which will include the module again in my project. Or delete the source of the dependent module, so my project will load the dependent module from the maven repository. But whenever I update my project from svn, the source of the dependent module is restored (I don't know why this even happens since its not part my project) and the cycle begins anew.
有 2 种方法允许我再次编译:取消选中 Ignored files 中的 pom,这将在我的项目中再次包含该模块。或者删除依赖模块的源,这样我的项目就会从maven仓库加载依赖模块。但是每当我从 svn 更新我的项目时,依赖模块的源就会恢复(我不知道为什么会发生这种情况,因为它不是我的项目的一部分)并且循环重新开始。
I googled this for a while since it gets really annoying. It became a problem with several excluded modules. I could rebuild the intellij-project from scratch but since a lot of IntelliJ settings were made (not related to the problem) I would rather solve this.
我用谷歌搜索了一段时间,因为它真的很烦人。它成为几个排除模块的问题。我可以从头开始重建 intellij 项目,但由于进行了很多 IntelliJ 设置(与问题无关),我宁愿解决这个问题。
Any help is appreciated, I guess I must be missing something
任何帮助表示赞赏,我想我一定错过了一些东西
采纳答案by herpnderpn
A collegue who has more in-depth knowledge of maven told me the answer:
一位对maven有更深入了解的同事告诉我答案:
The trick is not to remove the source module from the intellij project but to remove it from maven (in the maven projects tab in intellij). Intellij will ask then to remove the source module also from the intellij project and its finally gone.
诀窍不是从intellij 项目中删除源模块,而是从maven 中删除它(在intellij 的maven 项目选项卡中)。Intellij 将要求然后从 Intellij 项目中删除源模块,它最终消失了。
Right click on the maven project -> remove projects
右键单击maven项目->删除项目
Would not have guessed this makes such a difference.
没想到这会产生如此大的差异。
回答by Andrey Chaschev
Do any of these two points work for you:
以下两点中的任何一点是否适合您:
- NEWthere might be dependency in one of your sub-modules pointing to the removed artifact. To make sure it's the situation, you may want to rename your $HOME/.m2 and rebuild the project. If this is indeed the case, just search for the dependency in your poms and delete it from sub-modules
- right click on the parent
pom.xml
-> Maven -> Reimport - copy the project into a separate dir. File -> Import Project -> Choose newly created dir -> Choose Maven?
- NEW在您的子模块之一中可能存在指向已删除工件的依赖项。为了确保是这种情况,您可能需要重命名 $HOME/.m2 并重建项目。如果确实如此,只需在您的 poms 中搜索依赖项并将其从子模块中删除
- 右键单击父级
pom.xml
-> Maven -> 重新导入 - 将项目复制到单独的目录中。文件 -> 导入项目 -> 选择新创建的目录 -> 选择 Maven?
PS. Idea is excellent in maintaining the project structure in accordance with Maven project. Once you make a change to your pom, you need to reload the project. Idea can also automatically detect changes made to your pom.xml
and apply them to project. To enable this, press Ctrl+Shift+A, type 'maven auto', choose "Importing", checkbox "Import Maven project automatically";
附注。Idea在按照Maven项目维护项目结构方面非常出色。对 pom 进行更改后,您需要重新加载项目。Idea 还可以自动检测对您所做的更改pom.xml
并将其应用于项目。要启用此功能,请按Ctrl+Shift+A,键入“maven auto”,选择“导入”,选中“自动导入 Maven 项目”;
回答by jmkgreen
This may not relate directly to the OP, but...
这可能与 OP 没有直接关系,但是...
Using IntelliJ 2016.5, to remove a Maven module andit's underlying source code andremove it as a sub-module from the parent, go to the Project Files
tab, find the unwanted module and use the triangle symbol to open it, thendelete the entry that represents it on disk.
使用IntelliJ 2016.5删除 Maven 模块及其底层源代码并将其作为子模块从父模块中删除,转到Project Files
选项卡,找到不需要的模块并使用三角形符号将其打开,然后删除代表的条目它在磁盘上。
Hitting Delete
on the module itself will only mark it as hidden within the IDE.
点击Delete
模块本身只会将其标记为隐藏在 IDE 中。