You can use Maven properties in a
pom.xml file or in any resource that is being
processed by the Maven Resource plugin's filtering features. A property is
always surrounded by ${ and }. For
example, to reference the project.version property, one
would write:
${project.version}
There some implicit properties available in any Maven project, these implicit properties are:
project.*-
Maven Project Object Model (POM). You can use the
project.*prefix to reference values in a Maven POM. settings.*-
Maven Settings. You use the
settings.*prefix to reference values from your Maven Settings in~/.m2/settings.xml. env.*-
Environment variables like
PATHandM2_HOMEcan be referenced using theenv.*prefix. - System Properties
-
Any property which can be retrieved from the
System.getProperty()method can be referenced as a Maven property.
In addition to the implicit properties listed above, a Maven POM, Maven Settings, or a Maven Profile can define a set of arbitrary, user-defined properties. The following sections provide so detail on the various properties available in a Maven project.
When a Maven Project Property is referenced, the property
name is referencing a property of the Maven Project Object Model
(POM). Specifically, you are referencing a property
of the org.apache.maven.model.Model class which
is being exposed as the implicit variable project. When you reference a
property using this implicit variable, you are using simple dot notation
to reference a bean property of the Model object.
For example, when you reference ${project.version},
you are really invoking the getVersion() method
on the instance of Model that is being exposed as
project.
The POM is also represented in the
pom.xml document present in all Maven projects.
Anything in a Maven POM can be referenced with a
property. A complete reference for the POM structure
is available at http://maven.apache.org/ref/2.2.1/maven-model/maven.html.
The following list shows some common property references from the Maven
project.
project.groupIdandproject.version-
Projects in a large, multi-module build often share the same
groupIdandversionidentifiers. When you are declaring interdependencies between two modules which share the samegroupIdandversion, it is a good idea to use a property reference for both:<dependencies> <dependency> <groupId>${project.groupId}</groupId> <artifactId>sibling-project</artifactId> <version>${project.version}</version> </dependency> </dependencies> project.artifactId-
A project's artifactId is often used as the name of a deliverable. For example, in a project with WAR packaging, you will want to generate a WAR file without the version identifiers. To do this, you would reference the
project.artifactIdin your POM file like this:<build> <finalName>${project.artifactId}</finalName> </build> project.nameandproject.description-
The name and project description can often be useful properties to reference from documentation. Instead of having to worry that all of your site documents maintain the same short descriptions, you can just reference these properties.
project.build.*-
If you are ever trying to reference output directories in Maven, you should never use a literal value like
target/classes. Instead you should use property references to refer to these directories.-
project.build.sourceDirectory -
project.build.scriptSourceDirectory -
project.build.testSourceDirectory -
project.build.outputDirectory -
project.build.testOutputDirectory -
project.build.directory
sourceDirectory,scriptSourceDirectory, andtestSourceDirectoryprovide access to the source directories for the project.outputDirectoryandtestOutputDirectoryprovide access to the directories where Maven is going to put bytecode or other build output.directoryrefers to the directory which contains all of these output directories. -
project.baseUri-
If you need a valid URI for your project's base directory, you can use the
${project.baseUri}property. If your project is stored in the directory/tmp/simple,${project.baseUri}will resolve tofile:/private/tmp/simple/. - Other Project Property references
-
There are hundreds of properties to reference in a POM. A complete reference for the POM structure is available at http://maven.apache.org/ref/2.2.1/maven-model/maven.html.
For a full list of properties available on the Maven
Model object, take a look at the JavaDoc for the
maven-model project here http://maven.apache.org/ref/2.2.1/maven-model/apidocs/index.html.
Once you load this JavaDoc, take a look at the
Model class. From this
Model class JavaDoc, you should be able to
navigate to the POM property you wish to reference.
If you needed to reference the output directory of the build, you can
use the Maven Model JavaDoc to see that the output directory is
referenced via
model.getBuild().getOutputDirectory(); this
method call would be translated to the Maven property reference
${project.build.outputDirectory}.
For more information about the Maven Model module, the module which defines the structure of the POM, see the Maven Model project page at http://maven.apache.org/ref/2.2.1/maven-model.
