Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using maven and Intellij IDEA, how can I modify a dependency without needing to manually install it every time?

I'm using Intellij-IDEA 11. If there's a solution that works in 12, I'd be willing to upgrade for that.

I built a library that many projects depend on but the library changes often. This library is added to my project's pom.xml as a normal dependency:

    <dependency>
        <groupId>my.company</groupId>
        <artifactId>MyLibrary</artifactId>
    </dependency>

This is a typical series of steps I need to take when I add a feature to my project:

  1. Modify some code in my project
  2. Modify some code in the library I depend on
  3. Check to see if the feature works
  4. If not, repeat

Outside of my IDE (which happens to be Intellij-IDEA), this is a straight forward process: I add step 2.5 which is to cd into the dependency's project folder and then mvn install the library.

But I don't know a convenient way to do this in Intellij-IDEA. Ideally, I'd modify the source of the library inside Intellij, click the green play button and the IDE would figure out to use the modified sources of the library.

Right now, since the library is a dependency, it just uses what's already in my local repo. So modifying the source of the library doesn't have an affect until I manually mvn install it.

Note: I've figured out a trick that seems to work. If I modify the project's parent pom to include the library as a maven module and then include the same library as an intellij module, it uses that source instead of the jar in my local repo. But I don't like this solution because I'd never want to commit that modified pom (because the module has to point to a file system path that only exists on my local file system).

I've found a bug in the Intellij-IDEA bug tracker that seems to relate to this: http://youtrack.jetbrains.com/issue/IDEA-25146

like image 347
Daniel Kaplan Avatar asked Oct 21 '22 20:10

Daniel Kaplan


2 Answers

I found out a way to do this. First, you add the library's pom.xml in the Maven Projects tool window. Then you Edit your configurations so that they run the install goal of your library. And image of how to do this is provided below.

Click here for a full sized link How to mvn install a library before you run

like image 81
Daniel Kaplan Avatar answered Oct 27 '22 11:10

Daniel Kaplan


Open module setting (F4 on a module), go to Modules, select the dependencies tab in module that depepends on your library.

If the library is a module add a module dependency If the library isn't a module, I assume it gets built and put somewhere, add that directory to the module dependencies.

The higher up the list the higher its priority

like image 25
Alex Edwards Avatar answered Oct 27 '22 09:10

Alex Edwards