Get pom.xml property from CommandLine
I know the question is old but I spent some time looking for this.
To filter output you may use flags "-q -DforceStdout" where "-q" prevents output and "-DforceStdout" forces outputting result of plugin. E.g.:
BUILD_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
echo $BUILD_VERSION
will result in printing version of project from POM.
Second important problem I had was accessing "properties" which is explained in Nick Holt comment. To access properties you just access them directly
<project ...>
<version>123</version>
(...)
<properties>
(...)
<docker.registry>docker.registry.com</docker.registry>
(...)
</properties>
(...)
</project>
WRONG
mvn help:evaluate -Dexpression=project.properties.docker.registry -q -DforceStdout
OK
mvn help:evaluate -Dexpression=docker.registry -q -DforceStdout
If you know the name of the property you want, you can get the value with:
mvn help:evaluate -Dexpression=[property-name] | findstr /R ^^[^^\[INFO\]]
For example:
mvn help:evaluate -Dexpression=basedir | findstr /R ^^[^^\[INFO\]]
Will output:
C:\Users\nick\Local\Projects\example
This obviously assumes your building on a Windows box with the findstr
removing all the other logging that Maven does when it runs. You'll be able to do something similar on Unix with a grep
, but I leave that to you.