简体   繁体   English

如何永久删除Intellij Maven项目中的模块?

[英]How to remove Modules from a Intellij Maven Project permanently?

I am currently working on a larger scale Maven-based project in IntelliJIdea 12.1.6 Ultimate. 我目前正在IntelliJIdea 12.1.6 Ultimate中开展一个更大规模的Maven项目。 I have been working with IntelliJIdea since about 5 months. 我大约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. Intellij中已删除模块的pom.xml似乎被放置在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会将其保留在Ignored Files下,因此无法再次包含该模块。

2 ways allow me to compile again: Uncheck the pom from Ignored files, which will include the module again in my project. 2种方式允许我再次编译:从忽略文件中取消选中pom,这将在我的项目中再次包含该模块。 Or delete the source of the dependent module, so my project will load the dependent module from the maven repository. 或者删除依赖模块的源,因此我的项目将从maven存储库加载依赖模块。 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. 但每当我从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 任何帮助表示赞赏,我想我一定会遗漏一些东西

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项目中删除源模块,而是从maven中删除它(在intellij的maven项目选项卡中)。 Intellij will ask then to remove the source module also from the intellij project and its finally gone. 然后Intellij会要求从intellij项目中移除源模块,它最终消失了。

Right click on the maven project -> remove projects 右键单击maven项目 - >删除项目

Would not have guessed this makes such a difference. 不会猜到这会产生这样的差异。

Do any of these two points work for you: 这两点中的任何一点都适合你:

  • NEW there might be dependency in one of your sub-modules pointing to the removed artifact. NEW可能存在指向已删除工件的子模块之间的依赖关系。 To make sure it's the situation, you may want to rename your $HOME/.m2 and rebuild the project. 为了确保这种情况,您可能需要重命名$ HOME / .m2并重建项目。 If this is indeed the case, just search for the dependency in your poms and delete it from sub-modules 如果确实如此,只需在poms中搜索依赖项并从子模块中删除它
  • right click on the parent pom.xml -> Maven -> Reimport 右键单击父pom.xml - > Maven - > Reimport
  • copy the project into a separate dir. 将项目复制到一个单独的目录中。 File -> Import Project -> Choose newly created dir -> Choose Maven? 文件 - >导入项目 - >选择新创建的目录 - >选择Maven?

PS. PS。 Idea is excellent in maintaining the project structure in accordance with Maven project. 根据Maven项目维护项目结构的想法非常出色。 Once you make a change to your pom, you need to reload the project. 一旦你改变你的pom,你需要重新加载项目。 Idea can also automatically detect changes made to your pom.xml and apply them to project. Idea还可以自动检测对pom.xml所做的更改并将其应用于项目。 To enable this, press Ctrl+Shift+A , type 'maven auto', choose "Importing", checkbox "Import Maven project automatically"; 要启用此功能,请按Ctrl + Shift + A ,键入“maven auto”,选择“导入”,复选框“自动导入Maven项目”;

This may not relate directly to the OP, but... 这可能与OP没有直接关系,但......

Using IntelliJ 2016.5 , to remove a Maven module and it's underlying source code and remove 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, then delete 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中将其标记为隐藏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM