By using the project inheritance feature of Maven, we can share common build attributes such as properties
and dependencies
across all children. We can also aggregate modules and build them together.
When project inheritance is used, the parent is not aware of the child. In the case of project aggregation, each module is not aware of the aggregation.
We will now see how to combine and get the benefits of both.
simple-multi-module
. This has a subfolder child
, which is the module that is aggregated by the parent project.<groupId>com.packt.cookbook</groupId> <artifactId>simple-multi-module</artifactId> <packaging>pom</packaging> <version>1.0-SNAPSHOT</version>
module
section and specify the child:<modules> <module>child</module>
parent
element:<parent> <groupId>com.packt.cookbook</groupId> <artifactId>simple-multi-module</artifactId> <version>1.0-SNAPSHOT</version> </parent>
mvn clean package
[INFO] Reactor Summary: [INFO] [INFO] simple-multi-module ................................ SUCCESS [ 0.162 s] [INFO] Child Project ...................................... SUCCESS [ 2.411 s]
We have specified the parent
element in the child
pom to indicate who the parent is. We have also specified the child
project as a module in the parent pom. Thus, both the relationships—inheritance and aggregation—are defined.
When we build the parent project, it automatically builds the child by virtue of the modules
element. At the same time, the child project can be built independently as well.
The child project need not necessarily be a subfolder of the parent project. If it is elsewhere, as we have seen in the earlier recipes, it can be one of the following:
18.220.245.233