Skip to content

Instantly share code, notes, and snippets.

@loverdos
Created May 20, 2015 10:07
Show Gist options
  • Save loverdos/99bbd34097b8a00f52be to your computer and use it in GitHub Desktop.
Save loverdos/99bbd34097b8a00f52be to your computer and use it in GitHub Desktop.
Get maven project version from the shell
mvn help:evaluate -Dexpression=project.version | grep -e '^[^\[]'
@iopar
Copy link

iopar commented Oct 2, 2018

small improvement

grep version pom.xml | grep -v -e '<?xml|~'| head -n 1 | sed 's/[[:space:]]//g' | sed -E 's/<.{0,1}version>//g' | awk '{print $1}'

@KalivarapuReshma
Copy link

Latest version maven help plugin makes it even more easy.

mvn org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate -Dexpression=project.version -q -DforceStdout

@RobertoGraham
Copy link

@KalivarapuReshma Thanks for that command, I have used it to create this Docker Hub hook script to tag Maven projects with their version

@micw
Copy link

micw commented Mar 14, 2019

Grepping in POM does not honor maven core plug-ins that may alter the version at runtime (e.g. git branch versioning plug-in). So https://gist.github.com/loverdos/99bbd34097b8a00f52be#gistcomment-2721978 looks like the best solution to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment