Search code examples
eclipsemavenm2eclipsem2em2e-wtp

In m2e multimodule project delinking of classpath of imported projects


Let's say I have.

top/
|-parent/pom.xml
|-module1/pom.xml
|-module2/pom.xml ->depends on module1-SNAPSHOT.jar

One of the nice feature of m2e is that all that, if I import two multimodule modules in eclipse, and if one of them is dependent on other then their build output/classes directory get linked. I need not do a maven install on module1 still latest changes on module1 gets picked up by module2.

Although this is nice feature for smaller projects or fewer modules. But becomes pain when updating one project starts cascade build on all the other projects. Also adding more modules to eclipse will not spin off whole workspace build everytime I add or remove projects from workspace.

So here is the question: Is it possible for m2e to directly refer SNAPSHOT jar files from .m2 repository? And if I want latest of module1 to be made available to module2. I will have to maven install module1 which will create the SNAPSHOT.jar file in .m2 repository.

Note: I am using eclipse luna + j2ee.Version: Luna Service Release 2 (4.4.2) Build id: 20150219-0600. So I am using maven m2e-wtp which comes default with it.


Solution

  • You need to basically disable workspace resolution on the project you want to use snapshot jar references for. So right-click on say, your web project and then do

    Maven > Disable Workspace Resolution

    From now on, the web project won't reference its workspace project dependencies anymore, but will reference the jars that have been installed in your local Maven repository. Be aware though, it's all or nothing: You can't have some projects still referenced by your web project, while others are referenced by their snapshot jar. And that forces you to run mvn install on your project dependencies every time you make a modification.

    Another alternative is to close the projects you don't plan on modifying too often. Once closed, m2e will use the reference from the local Maven repo.