How to get Maven project version to the bash command line

The Maven Help Plugin is somehow already proposing something for this:

  • help:evaluate evaluates Maven expressions given by the user in an interactive mode.

Here is how you would invoke it on the command line to get the ${project.version}:

mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate \
    -Dexpression=project.version

As noted in the comments by Seb T, to only print the version without the maven INFO logs, additionally use -q -DforceStdout:

mvn help:evaluate -Dexpression=project.version -q -DforceStdout

Leave a Comment