Java Reference
In-Depth Information
parents for others. For instance, if we want to use the pom from listing 10.1 for our
parent, all we have to do is change its packaging value to pom . Parent and aggregation
(multimodule) projects can have only pom as a packaging value. We also need to
define in our parent the child modules, as shown in listing 10.2.
Listing 10.2
Child modules for parent pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.manning.junitbook</groupId>
<artifactId>example-pom</artifactId>
<packaging>pom</packaging>
<version>2.0-SNAPSHOT</version>
B
<modules>
<module>example-module</module>
</modules>
</project>
This listing is an extension of listing 10.1. We declare that this pom is an aggregation
module by declaring the package to be of pom type B and adding a modules section
C . The modules section lists all the child modules that our module has, by providing
the relative path to the project directory ( example-module ).
Listing 10.3 shows the child pom.xml.
C
Listing 10.3
Pom.xml that inherits the parent pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.manning.junitbook</groupId>
<artifactId>example-pom</artifactId>
<version>2.0-SNAPSHOT</version>
</parent>
<artifactId>example-child</artifactId>
</project>
Remember that this pom.xml resides in the directory that the parent pom.xml has
declared ( example-module ).
There are two things are worth noticing here. First, because we inherit from some
other pom , there's no need to specify groupId and version for the child pom ; Maven
expects they're the same as the parent's .
Going with the similarity to Java, it seems reasonable to ask, “What kind of objects
can pom s inherit from their parents?” Here's a list of all the elements that a pom can
inherit from its parent:
Dependencies
Developers and contributors
Plug-in lists
Reports lists
 
 
 
Search WWH ::




Custom Search