There a serveral elements that can exist under the POM’s project element. They can be devided into four groups: Basics, Build Settings, More Project Information and Environment Settings.
Contents
Basics
groudId, artifactId, version
The groupId
, artifactId
, and version
values form the project’s fully qualified artifact name. This is in the form of groupId:artifactId:version
. The three fields mark a specific place in a repository, acting like a coordinate system for Maven projects.
parent
Maven supports the concept of project inheritance. Unless explicitly set, all POM’s extend Maven’s Super POM, Maven’s default POM. To inherit form a different POM, use the parent
element. For example:
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>nl.ersoftware.app</groupId>
<artifactId>my-parent</artifactId>
<version>2.0.0</version>
</parent>
<groupId>nl.ersoftware.app</groupId> <!-- optional, inherited from parent -->
<artifactId>my-module</artifactId>
<version>1.0.0-SNAPSHOT</version>
</project>
Note that for the parent POM, the packaging type must be “pom”:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>nl.ersoftware.app</groupId>
<artifactId>my-parent</artifactId>
<version>2.0.0</version>
<packaging>pom</packaging>
</project>
packaging
The packaging
element specifies the type of artifact the project produces. The packaging type is required to be “pom” for parent and aggregation (multi-module) projects. Other values include “jar”, “war” and “rar” and “ejb”. The default is “jar”. Plugins may add types. When, for example, creating an RPM as primary arrtifact with the RPM plugin, the packaging value should be set to “rpm”.
dependencies
dependencyManagement
The dependencyManagement
element is used by a POM to help manage dependency information across all of its children. If the parent project uses dependencyManagement
to define a dependency on junit:junit:4.12
, then POMs inheriting from this one can set their dependency giving the groupId=junit
and artifactId=junit
only and Maven will fill in the version set by the parent.
modules
A project with modules is known as a multi-module, or aggregator project.
<packaging>pom</packaging>
<modules>
<module>my-project</module>
<module>another-project</module>
<module>third-project/pom-example.xml</module>
</modules>
Properties
Maven properties are value placeholders. Their values are accessible anywhere within a POM by using the notation ${X}
, where X is the property. They come in five different styles:
env.X
: Will return the shell’s environment variable X.project.x
: A dot (.) notated path in the POM will contain the corresponding element’s value.settings.x
: A dot (.) notated path in the settings.xml will contain the corresponding element’s value.java.x
: Java System Properties.x
: Set within a<properties />
element in the POM.
Build Settings
More Project Information
Environment Settings
Project Inheritance
The Super POM is Maven’s default POM. All POMs extend the Super POM unless explicitly set. You can also introduce your own parent POMs by specifying the parent element in the POM, for example: