简体   繁体   中英

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. 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.

To solve this I need to do the following:

  1. Open Module Settings on the module using the internal Maven dependency
  2. Find and remove the internal Maven module in the Dependencies list
  3. Add a new Module Dependency and then select the imported module that corresponds to the internal Maven dependency

Is there any way to have IDEA figuring out this automatically or do I have to do this manual procedure over and over?

To add another maven project (that is not part of your main project) as a dependency:

  1. open you main project
  2. in Maven Projects Tool Window click on green + button and select pom.xml of a dependency
  3. repeat 2 as required

Source: 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. If you are referring to your maven dependencies as intellij modules, it will get confused.

You should either:

  1. Change these maven dependencies to be maven modules .
  2. Remove these intellij modules as intellij modules and set up your maven build so you can download the source from your maven dependencies.

Lets say you have a maven module A which has module B as a dependency. 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.

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.

If this does not work, then you should report a bug.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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