Language and Page Formatting Options
3.3. Create an Aggregate Maven Project
A complete application typically consists of multiple Maven projects. As the number of projects grows larger, however, it becomes a nuisance to build each project separately. Moreover, it is usually necessary to build the projects in a certain order and the developer must remember to observe the correct build order.
To simplify building multiple projects, you can optionally create an aggregate Maven project. This consists of a single POM file (the aggregate POM), usually in the parent directory of the individual projects. The POM file specifies which sub-projects (or modules) to build and builds them in the specified order.
Maven also supports the notion of a parent POM. A parent POM enables you to define an inheritance style relationship between POMs. POM files at the bottom of the hierarchy declare that they inherit from a specific parent POM. The parent POM can then be used to share certain properties and details of configuration.
The details of how to define and use a parent POM are beyond the scope of this guide, but it is important to be aware that a parent POM and an aggregate POM are not the same thing.
Quite often, you will see examples where a POM is used both as a parent POM and an aggregate POM. This is acceptable for small, relatively simple applications, but is not recommended. In general, it is better to define separate POM files for the parent POM and the aggregate POM.
Create an aggregate POM
To create an aggregate POM for your getting started application, use a text editor to create a
pom.xmlfile in the
get-starteddirectory and add the following contents to the file:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <groupId>org.fusesource.example</groupId> <artifactId>get-started</artifactId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging> <modelVersion>4.0.0</modelVersion> <name>Getting Started :: Aggregate POM</name> <description>Getting Started example</description> <modules> <module>cxf-basic</module> <module>camel-basic</module> </modules> </project>
As with any other POM, the
versionmust be defined, in order to identify this artifact uniquely. But the
packagingmust be set to
pom. The key portion of the aggregate POM is the
moduleselement, which defines the list of Maven sub-projects to build and defines the order in which the projects are built. The content of each
moduleelement is the relative path of a directory containing a Maven project.
Building with the aggregate POM
Using the aggregate POM you can build all of sub-projects in one go, by entering the following at a command prompt:
cd get-started mvn install