152

I know there is a list of all predefined Maven properties (you know like project.build.sourceEncoding, or project.build.sourceDirectory). I once saw the list but I just can't find it again.

7 Answers 7

156

Do you mean this one?

https://web.archive.org/web/20150520200505/https://docs.codehaus.org/display/MAVENUSER/MavenPropertiesGuide

I also moved its content to a GitHub repo:

https://github.com/cko/predefined_maven_properties/blob/master/README.md

5
  • 1
    Usually, when you edit pom.xml in Intellij IDEA, it helps greatly by providing options for anything that looks like a Maven property (e.g. ${...}) Feb 17, 2016 at 22:29
  • mvn help:effective-pom stands as a great tool for discovering properties available. maven.apache.org/plugins/maven-help-plugin/…
    – Petra Kahn
    Jul 4, 2016 at 15:01
  • 2
    Also review this page in the Maven wiki : cwiki.apache.org/confluence/display/MAVEN/…
    – Guss
    Mar 22, 2017 at 13:29
  • 2
    Doesn't include "everything" like [WARNING] The expression ${artifactId} is deprecated. Please use ${project.artifactId} instead. but includes most ;)
    – rogerdpack
    Feb 3, 2020 at 22:18
  • where is project.build.sourceDirectory?
    – caduceus
    Mar 9, 2021 at 7:56
34

Take a look at section 9.2.: Maven Properties of the free online book Maven: The Complete Reference.

27

Looking at the "effective POM" will probably help too. For instance, if you wanted to know what the path is for ${project.build.sourceDirectory}

you would find the related XML in the effective POM, such as: <project> <build> <sourceDirectory>/my/path</sourceDirectory>

Also helpful - you can do a real time evaluation of properties via the command line execution of mvn help:evaluate while in the same dir as the POM.

1
  • Seems some are from the XML tree and some are from "just normal properties" FWIW...
    – rogerdpack
    Feb 3, 2020 at 21:59
17

I think the best place to look is the Super POM.

As an example, at the time of writing, the linked reference shows some of the properties between lines 32 - 48.

The interpretation of this is to follow the XPath as a . delimited property.

So, for example:

${project.build.testOutputDirectory} == ${project.build.directory}/test-classes

And:

${project.build.directory} == ${project.basedir}/target

Thus combining them, we find:

${project.build.testOutputDirectory} == ${project.basedir}/target/test-classes

(To reference the resources directory(s), see this stackoverflow question)


<project>
    <modelVersion>4.0.0</modelVersion>
    .
    .
    .
    <build>
        <directory>${project.basedir}/target</directory>
        <outputDirectory>${project.build.directory}/classes</outputDirectory>
        <finalName>${project.artifactId}-${project.version}</finalName>
        <testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
        <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
        <scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
        <testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
        <resources>
            <resource>
                <directory>${project.basedir}/src/main/resources</directory>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>${project.basedir}/src/test/resources</directory>
            </testResource>
        </testResources>
        .
        .
        .
    </build>
    .
    .
    .
</project>
9

I got tired of seeing this page with its by-now stale references to defunct Codehaus pages so I asked on the Maven Users mailing list and got some more up-to-date answers.

I would say that the best (and most authoritative) answer contained in my link above is the one contributed by Hervé BOUTEMY:

here is the core reference: http://maven.apache.org/ref/3-LATEST/maven-model-builder/

it does not explain everyting that can be found in POM or in settings, since there are so much info available but it points to POM and settings descriptors and explains everything that is not POM or settings

7
  • 3
    The very question asks for a link, so I think your concern is misplaced. This question does not ask "How do I do X" but "Where can I find X". Sep 8, 2015 at 19:00
  • 2
    oops, you are right - it's the question that doesn't fit into this site :-) Thanks for the heads up - voted to close
    – kleopatra
    Sep 8, 2015 at 22:37
  • 1
    And yet, it's a question that comes up again and again as was readily conceded in the many answers my mailing list post received.. The point is that Maven does not document this area well or concisely enough. There should be a page prominently displayed on their website for this kind of info and there isn't. It's not immediately clear even from these links, that any element of the POM reference or other places mentioned can be converted to a ${dotted.notation} expression and used in a POM file. This question thus serves a useful purpose and would need to be updated if it gets moved again. Sep 9, 2015 at 14:19
  • 1
    asking for external resources is off scope of this site, if all would play by the rules there wouldn't be any where is X questions ;-)
    – kleopatra
    Sep 9, 2015 at 15:08
  • 3
    I don't understand the rules sometimes. It's a perfectly valid question, and people have been more than willing to answer it in the past. By being such sticklers for such rules Stack Overflow cuts off its nose to spite its face. Sep 10, 2015 at 14:21
4

This link shows how to list all the active properties: http://skillshared.blogspot.co.uk/2012/11/how-to-list-down-all-maven-available.html

In summary, add the following plugin definition to your POM, then run mvn install:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <phase>install</phase>
            <configuration>
                <target>
                    <echoproperties />
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>
1

Most of these answers provide old links, rely on non-authoritative books, or reference to someone's personal collection. Even the http://maven.apache.org/ref/3-LATEST/maven-model-builder/ referenced in one answer doesn't contain a complete list. Try searching the page for project.build.directory, for example.

There doesn't seem to exist an authoritative declarative list unfortunately, but I believe there is an authoritative documentation of programmatic access: the API reference for org.apache.maven.model.Model. For example to discover and/or learn about project.build.directory:

  1. Model.getBuild()
  2. Build
  3. Build.getDirectory()

Get the directory where all files generated by the build are placed. The default value is target.

Maven Model and Maven Project Descriptor are also useful.

If someone had the time, they could programmatically walk a minimal org.apache.maven.model.Model to at least discover the default properties and generate some HTML/Markdown reference page. (I realize that dynamically the model will be unique at build time based upon the project.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.