The config shown uses the same POM as both the parent and aggregator. Documentation will also discuss inheritance vs. multi-module. A parent POM passes values to its children, while an aggregator POM manages a group of subprojects or modules. Section 3.6.2 of the Sonatype Maven Book goes into a lot more detail.
In my experience, Maven builds work better when the parent and aggregator POMs are separate.
The reason has to do with dependencies, how Maven determines build order, and how Maven runs commands. If your sample structure was like this, with a separate parent and aggregator, where test1 and test2 inherited from parent:
project (aggregator POM)
|- parent
|- test1
|- test2
then the Maven build order will look like this (assuming dependencies are defined correctly of course):
- parent
- test1
- test2
- aggregator
A command like mvn clean install site
will start with the parent project, cleaning and building, installing to the local artifact repository, then generating the project site. It repeats this command sequence in order for each project shown. Because the aggregator is separate, it may have separate configuration to perform report aggregation for tests, coverage and javadoc. The aggregator runs last, so the coverage databases and intermediate javadoc files for the modules already exist, ready to be appropriately combined.
When the parent and aggregator are the same POM as you have it, the build order is:
- parentAggregator
- test1
- test2
When you run mvn clean install site
now, Maven must build the parent POM (here, parentAggregator) so it has the information required for the child modules depending on it. parentAggregator is also the aggregator, so Maven will happily run any aggregating reports as part of site
. Of course, the child modules haven't been built yet, so there are no coverage databases or intermediate javadoc files to aggregate. Or, possibly worse, old files exist so the aggregator operates on those files. After the parent-aggregator builds, the child modules build, and then the command exits. There is no final aggregation step at the end of the build. The overall results are probably not what you want.
This phenomenon can cause problems during multi-module project release builds, painful enough that developers wrote a versions-maven-plugin mojo to help correct them. The issue:
If you have a multi-module build where the aggregator pom (i.e. the one with packaging of pom and the modules section) is also the parent referenced by its child modules, and the aggregator version does not match the version specified in the parent section of the child modules, Maven will not let you build the project.