简体   繁体   English

Intellij IDEA可以自动将Maven依赖项替换为模块依赖项吗?

[英]Can Intellij IDEA automatically replace Maven dependencies with module dependencies?

I'm working with a Java project in Intellij IDEA where we have a lot of internal, standalone, Maven dependencies. 我正在Intellij IDEA中使用Java项目,那里有很多内部的,独立的Maven依赖项。 I have the source code for these dependencies imported into my IDEA project as modules, but when I select Go To -> Implementation(s) on a class that is part of an internal Maven dependency (and that I have also imported as a module in my project) I'm navigated to a decompiled view of the class in the Maven dependency (jar) and not the source code file of that class that I imported as a module. 我将这些依赖项的源代码作为模块导入到我的IDEA项目中,但是当我在属于内部Maven依赖项的类上选择Go To- > Implementation(s)时(并且我也已将其作为模块导入到我的项目),我导航到Maven依赖项(jar)中该类的反编译视图,而不是我作为模块导入的该类的源代码文件。

To solve this I need to do the following: 为了解决这个问题,我需要执行以下操作:

  1. Open Module Settings on the module using the internal Maven dependency 使用内部Maven依赖项在模块上打开模块设置
  2. Find and remove the internal Maven module in the Dependencies list 在“ 依赖关系”列表中查找并删除内部Maven模块
  3. Add a new Module Dependency and then select the imported module that corresponds to the internal Maven dependency 添加一个新的模块依赖项 ,然后选择与内部Maven依赖项对应的导入模块

Is there any way to have IDEA figuring out this automatically or do I have to do this manual procedure over and over? 有什么方法可以让IDEA自动解决这个问题,还是我必须一遍又一遍地执行此手动过程?

To add another maven project (that is not part of your main project) as a dependency: 要将另一个maven项目(不属于您的主项目)添加为依赖项:

  1. open you main project 打开您的主项目
  2. in Maven Projects Tool Window click on green + button and select pom.xml of a dependency 在Maven项目工具窗口中,单击绿色+按钮,然后选择依赖项的pom.xml
  3. repeat 2 as required 根据需要重复2

Source: https://www.jetbrains.com/idea/help/maven-projects-tool-window.html?search=maven%20project 来源: https : //www.jetbrains.com/idea/help/maven-projects-tool-window.html?search=maven%20project

I'd suggest that you are using intellij incorrectly in this example. 我建议您在此示例中使用intellij错误。 If you are referring to your maven dependencies as intellij modules, it will get confused. 如果您将Maven依赖项称为intellij模块,则会感到困惑。

You should either: 您应该:

  1. Change these maven dependencies to be maven modules . 将这些Maven依赖项更改为Maven模块
  2. Remove these intellij modules as intellij modules and set up your maven build so you can download the source from your maven dependencies. 删除这些intellij模块作为intellij模块,并设置您的Maven构建,以便您可以从Maven依赖项下载源代码

Lets say you have a maven module A which has module B as a dependency. 假设您有一个Maven模块A,其中的模块B作为依赖项。 If you import both modules into one IntelliJ project, IntelliJ will automatically use the imported module B instead of the maven artifact from repository - but you must import it as a maven module. 如果将两个模块都导入到一个IntelliJ项目中,则IntelliJ将自动使用导入的模块B代替仓库中的maven工件-但您必须将其作为maven模块导入。

If you then run some test or application via IntelliJ from module A, it will use it's own compiled classes from module B and not the maven artifact from repository, navigation in the code and everything else will work as expected. 然后,如果您通过模块A的IntelliJ运行某些测试或应用程序,它将使用模块B自身的已编译类,而不使用存储库中的Maven工件,代码中的导航以及所有其他操作将按预期进行。

If this does not work, then you should report a bug. 如果这不起作用,则应报告一个错误。

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

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