开发者

Where is the list of predefined Maven properties

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 l开发者_高级运维ist but I just can't find it again.


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


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


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.


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>


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


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>


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.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜