The MavenPropertiesGuide that was on the wiki of Codehaus has been an incredible useful go-to resource for me for a long time. Since Codehaus is no more, that page also disappeared. The Wayback Machine has a copy, but it's incredibly slow, and hard to find. So here is a mostly-verbatim copy of it, "sic", for my and your reference.

Captured on May 20 2015, last updated on December 28 2012. Noted authors are Jasper Molenmaker and Frank Griswold.

Intro

Because I couldn't find a clear overview of which properties are availabe in maven2 I started this page. It is a collection of things found in the offcial maven documentation and postings to the maven user mailing list.

Note: In Maven 3.0, all pom.* properties are deprecated. Use project.* instead!

Built-in properties

  • ${basedir} represents the directory containing pom.xml
  • ${version} equivalent to ${project.version} (deprecated: ${pom.version})

Pom/Project properties

All elements in the pom.xml, can be referenced with the project. prefix. This list is just an example of some commonly used elements. (deprecated: {pom.} prefix)

  • ${project.build.directory} results in the path to your "target" directory, this is the same as ${pom.project.build.directory}
  • ${project.build.outputDirectory} results in the path to your "target/classes" directory
  • ${project.name} refers to the name of the project (deprecated: ${pom.name} ).
  • ${project.version}refers to the version of the project (deprecated: or ${pom.version}).
  • ${project.build.finalName} refers to the final name of the file created when the built project is packaged

Local user settings

Similarly, values in the user's settings.xml can be referenced using property names with settings. prefix.

  • ${settings.localRepository} refers to the path of the user's local repository

Environment variables

Environment variables can be referenced using the env prefix

  • ${env.M2_HOME} returns the Maven2 installation path.
  • ${java.home} specifies the path to the current JRE_HOME environment use with relative paths to get for example:
    <jvm>${java.home}../bin/java.exe</jvm>

Java system properties

All Java System Properties defined by the JVM.

Custom properties in the POM

User defined properties in the pom.xml.

<project>
...
  <properties>
    <my.filter.value>hello</my.filter.value>
  </properties>
...
</project>
  • ${my.filter.value} will result in hello if you inserted the above XML fragment in your pom.xml

Parent Project variables

How can parent project variables be accessed?

You can use the prefix: ${project.parent}.

A good way to determine possible variables is to have a look directly at the API. I'm currently using Maven 2.2.1, and to access the Parent you can use ${project.parent}. This will return an org.apache.maven.project.MavenProject instance.

To access the parent version: ${parent.version}.

Reflection Properties

The pattern ${someX.someY.someZ} can simply sometimes mean getSomeX().getSomeY().getSomeZ(). Thus, properties such as ${project.build.directory} is translated to getProject().getBuild().getDirectory().

17 Comments

  1. Franz Allan Valencia See

    Good day,

    Here is my list. Some of these are not yet on the list and some of them are already are. And I must admit that I am still not yet acquainted with some of them.

    I also placed here where I got these from just in case somebody wants to know how I came up with this list and where to get more info (code-reading-wise).

    Not sure though if this is the complete list (excluding plugin expressions and user-defined properties).

    * project (from [1])
        o project.distributionManagementArtifactRepository
        o project.artifact
        o project.parent
        o project.file
        o project.artifacts
        o project.parentArtifact
        o project.pluginArtifacts
        o project.remoteArtifactRepositories
        o project.pluginArtifactRepositories
        o project.attachedArtifact
    * settings (from [2])
        o settings.offilne
        o settings.interactive
    * rootless (from [3])
        o localRepository
        o reactorProjects
    * java properties (from [4])
        o java.version
        o java.vendor
        o java.vendor.url
        o java.home
        o java.vm.specification.version
        o java.vm.specification.vendor
        o java.vm.specification.name
        o java.vm.version
        o java.vm.vendor
        o java.vm.name
        o java.specification.version
        o java.specification.vendor
        o java.specification.name
        o java.class.version
        o java.class.path
        o java.library.path
        o java.io.tmpdir
        o java.compiler
        o java.ext.dirs
        o os.name
        o os.arch
        o os.version
        o file.separator
        o path.separator
        o line.separator
        o user.name
        o user.home
        o user.dir

    Thanks,
    Franz

    [1] http://svn.apache.org/repos/asf/maven/components/trunk/maven-core/src/main/resources/META-INF/maven/plugin-expressions/project.paramdoc.xml
    [2] http://svn.apache.org/repos/asf/maven/components/trunk/maven-core/src/main/resources/META-INF/maven/plugin-expressions/rootless.paramdoc.xml
    [3] http://svn.apache.org/repos/asf/maven/components/trunk/maven-core/src/main/resources/META-INF/maven/plugin-expressions/settings.paramdoc.xml
    [4] http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html#getProperties

    9 20, 2006

  2. John Martin

    Is there a way to pick up the path name to the settings.xml file that might have been provided with the -s switch?

    9 29, 2006

  3. Bjorn De Bakker

    Is it possible to add a property to your pom.xml? I mean, doing something like this:
    <version>${app.version}</version>

    When you want to compile, just provide the value for the app.version via the command line. The problem is that we have several builds for one application (local, server, ...) and for that we need multiple properties-files, to change settings according to the location we're deploying it to.

    10 27, 2006

  4. Franz Allan Valencia See

    Good day to you, Bjorn,

    You might want to use your POM's dependencyManagement for that.

    Cheers,
    Franz

    11 13, 2006

  5. Tjeerd Verhagen

    Hi Bjorn,

    Or maybe an other possibility is to use the Maven 2 profiles.
    See http://altuure.blogspot.com/2006/11/maven-profiles.html for an example.

    Cheers, Tjeerd

    12 12, 2006

  6. Emmanuel Hugonnet

    Maybe you should explain how you can set such a property from a MOJO.
    I would like to know this very much ;-)

    12 15, 2006

  7. Jamie Burrell

    Not sure if anyone else finds it useful (I know I did), but I have submitted a patch to plexus-utils that allows selection of properties from lists within the POM: http://jira.codehaus.org/browse/PLXUTILS-37
    For example, given the following in the POM:

    pom.xml

    <project>
      ...
      <developers>
        <developer>
          <id>myUserId</id>
          <name>Jamie Burrell</name>
          <email>This email address is being protected from spambots. You need JavaScript enabled to view it.</email>
          <roles>
            <role>developer</role>
          </roles>
          <timezone>0</timezone>
        </developer>
        <developer>
          <id>herUserId</id>
          <name>Jane Doe</name>
          <email>This email address is being protected from spambots. You need JavaScript enabled to view it.</email>
          <organization>Doe Solutions</organization>
          <roles>
            <role>developer</role>
          </roles>
          <timezone>0</timezone>
        </developer>
      </developers>
      ...
    </project>
    

    Referencing ${project.developers.0.id} in the POM would then return "myUserId".

    Not useful to everyone, but also not harmful, and allows access to all the list props on the POM (such as developers, contributors, profiles etc). I've been using it to automate directory path filtering for each developer (on *nix, the path is /home/group/userid).

    Comments welcome.

    Cheers, Jamie

    6 06, 2007

  8. Nicolas Kyriazopoulos-Panagiotopoulos

    Hi!

    It's not exactly the best place to ask, but, do you know how can we declare a custom property that is a collection? Something like

    <properties>
    <my.filter.value>
    <items>
    <item>hello</item>
    <item>world</item>
    </items>
    </properties>Thaanks in advance!

    11 15, 2007

  9. Amit

    Hi all,

    Thanks for the list. I am wondering if their is any Maven variable that can be used to obtain date of the system, I want to use this as the folder name in which my maven builds will go in to.

    I fancy for something like <directory>"Date"</directory> in the build tag of pom.xml.

    Please guide on the same.

    Regards,

    Amit

    12 26, 2007

  10. QA_2

    Thanks for the list of the default ones! I was looking all over maven.apache.org for something like that. They should really clean this up, make sure it's complete, and then put it up.

    On a related note, does anyone know if it's possible to provide a pom.xml file with a standard Java properties file and have maven read the file and set those properties accordingly?

    1 24, 2008

  11. Thomas Franconville

    Is it possible to know into a variable the goal launched ?

    I want with a developper profile do the tests only with a maven test. So like that, the maven install will be faster. The idea is to use this variable with the skip test.

    10 16, 2008

  12. Chris Laprun

    ${maven.repo.local} doesn't seem to be working anymore...

    11 24, 2008

  13. astroxl

    how can i reference the assembly id in my descriptor file?

    <build>
       <plugins>
          <plugin>
             <artifactId>maven-assembly-plugin</artifactId>
             <executions>
                <execution>
                   <id>mysql</id>
                   <phase>package</phase>
                   <goals>
                      <goal>single</goal>
                   </goals>

                   <configuration>
                      <descriptors>
                         <descriptor>src/main/assemblies/descriptor.xml</descriptor>

                         <!-- I want to reference the assembly id "mysql" in this descriptor.xml, how to do that ? -->
                      </descriptors>
                   [...]

                   </configuration>

                </execution>

             </executions>

          <plugin>

       <plugins>

    thanks alot!

    3 19, 2009

  14. Nicolas Toublanc

    Since Maven 2.1, you can use build timestamp as property:

    maven.build.timestamp

    and configure the format:

    <maven.build.timestamp.format>yyyyMMdd-HHmm</maven.build.timestamp.format>

    http://maven.apache.org/guides/introduction/introduction-to-the-pom.html

    12 22, 2009

  15. Marco Soldati

    In response to Nicolas Kyriazopoulos-Panagiotopoulos posting of >2 years ago. Hopefully it will help someone else:

    Add your list to a CDATA section

        <property>
            <site.links>
                <![CDATA[<links>
                    <item name="Helio Home" href="http://www.helio-vo.eu/" />
                    <item name="Wiki" href="http://ourwiki.com" />
                    <item name="Helio Dev" href="http://ourdevserver.com" />
                </links>]]>
            </site.links>
        <property>
    

    4 01, 2010

  16. Johann Renck

    Also you can just add the following to check which properties are available:

        ....
    <plugin> <artifactId>maven-antrun-plugin</artifactId> <version>1.6</version> <executions> <execution> <phase>install</phase> <configuration> <tasks> <echoproperties /> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> </plugins> </build>

    10 09, 2011

  17. Pino Silvaggio

    For anyone interested,

    I created this new plugin where it sets a property pointing to the artifact file for each selected project dependency. Each property name will have a base name in form of groupId:artifactId:type:[classifier][.relative][.suffix]. This is similar to the dependency:properties goal but with additional features, like filtering and relative paths.

    Result:

    junit:junit:jar=/home/user/.m2/repository/junit/junit/4.8.2/junit-4.8.2.jar

    or

    junit:junit:jar.relative=../../../.m2/repository/junit/junit/4.8.2/junit-4.8.2.jar

    or

    junit:junit:jar.relative.someSuffix=../../../.m2/repository/junit/junit/4.8.2/junit-4.8.2.jar

    http://bitstrings.github.com/sites/dependencypath-maven-plugin/index.html
    (home:bitstrings.org)

    The m2e connector will soon be released too.

    11 20, 2011