2

I'm trying to create an aggregate POM to build all our projects from a clean slate. Let's say I have a parent project and 2 code projects. These are all in different source trees.

Parent:

<groupId>com.example</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

Project A:

<parent>
    <groupId>com.example</groupId>
    <artifactId>parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath/>
</parent>

<artifactId>project-A</artifactId>
<packaging>jar</packaging>

Project B:

<parent>
    <groupId>com.example</groupId>
    <artifactId>parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath/>
</parent>

<artifactId>project-B</artifactId>
<packaging>jar</packaging>

Now I'm trying to create a separate aggregator POM to build all of these together, like so:

<groupId>com.example</groupId>
<artifactId>aggregator</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
    <module>path/to/parent</module>
    <module>path/to/project-A</module>
    <module>path/to/project-B</module>
</modules>

mvn clean install on the aggregator project fails, because the reactor cannot find the <parent> of the two code projects. The reason is obvious - the parent project is part of the reactor and so the artifact does not exist at the start of the build.

Is there a way to achieve this reactor build?

metacubed
  • 7,031
  • 6
  • 36
  • 65
  • If your parent is part of the reactor than an aggregator does not make sense. You should structure your projects according the needed structure which means root level parent and child modules into sub levels...and the parent should than contain the module entries...and everything will work.. – khmarbaise Jul 09 '16 at 12:31
  • @khmarbaise the parent is a company-wide root pom, so I cannot change its contents. However I do want to pull in any changes to the parent before building my own projects. – metacubed Jul 10 '16 at 01:47

3 Answers3

2

You need to specify following part in your parent POM:

<modules>
<module>path/to/parent</module>
<module>path/to/project-A</module>
<module>path/to/project-B</module> 
</modules>
2

Than you should create a parent:

 pom.xml (inherit from company)
   +--- project-A
   +--- project-B 

This will solve those problems...

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
2

You just need to mvn install the parent once.

Then it will be in your local repository and the aggregator will find it. From that point on, the reactor will recognize the inheritance and always rebuild the parent first.