Best way to add dependency to external maven module

I have a maven module that for some practical reasons I need to execute having in the classpath an external maven module, from another project, without having to include this dependency explicitly in the POM, but just by means of the IntelliJ configuration.
In Eclipse it is very easy to add a dependency on an external project, but I do not arrive to do that in IntelliJ.

What I have tried:
In my first attempt I tried building first, with maven, the project I depend from. Then I just added the generated jars as libraries in the project where I need them.
This partially worked, I could see the classes from the projects I depended from but I could not see in the classpath the dependencies of those classes in the jars.

Afterwards I tried with modifying the definition of the library in the "Project Structure" configuration, this time not using the jars of the external module, but attempted to generate a Maven dependency on such a module.
The problem with this approach is that when I configure the library as created "From Maven", IntelliJ cannot find which library I am talking about when I type its name in the text box, although such a library is installed in the Maven local repository, since I previously did a maven install in the external project.

What is the best (easiest) way to add a dependency to an external module (i.e., in a different project) so all the classes, resources, AND the dependencies of this module, will be in the classpath? In Eclipse it is possible to indicate that a project depends on another project and automatically all the needed dependencies are automatically configured. How can I do something equivalent in IntelliJ?


1 comment
Comment actions Permalink

I also tried selecting the module in the Project Structure window, then choosing the Dependencies tab and adding a new Module Dependency. However, from this list I can choose only modules in the same project, while I need the dependency to be on a module located in an external IntelliJ project.


Please sign in to leave a comment.