Search code examples
javaeclipsemavenmaven-assembly-plugin

Maven dependency on other Maven projects


I have multiple maven projects, to add dependencies between them I just add it to the POM, for example :

    <dependency>
        <groupId>com.company</groupId>
        <artifactId>XMLManagement</artifactId>
        <version>1.0</version>
    </dependency>

I am working with eclipse, and everything runs and works great until I try to release a jar.

**Problem1: ** Maven throws an error because it can't find the jars of the other maven projects it depends on in the local repository, and this means that I have to figure out myself the dependencies between the projects, and go to each and every project in the right order and run "mvn clean install"

This does not seem logical since that is the main purpose of maven, there must be a way to tell maven to do it himself.

**Problem2: ** If project A depends on B that depends on C, and I want to use C in A then in eclipse its enough that I added B in the POM of A and it works, but when I run "mvn clean install" maven throws an error that it is missing dependency of C. This means I have to add the dependency between A and C, which doesn't make sense because in eclipse I already see it under "Maven Dependencies", so if eclipse recognizes it why mvn clean install doesn't?

Note that I am able to produce the jar I need at the end, but only after a lot of hard work as described above.

I know I can use something like nexus or artifactory, but it's an overkill for me and I want to be able to do it in local repository.

I am looking for the proper way to do it, any suggestions?


Solution

  • What you need is a top-level pom that lists each of the things you want build as modules. In maven jargon, this is known as a reactor build.

    Something like:


     <groupId>this.that</groupId>
     <artifactId>build.root</artifactId>
     <name>A name</name>
     <packaging>pom</packaging>
     <modules>
      <module>../a.b</module>
      <module>../a.c</module>