Prerequisite: In your project you need the file src/main/resources/config.properties
Of course you can adapt to using whatever file you want.
Note that this assumes you're using a "version=" property in your config.properties file
Step 1: Add the maven plugin to run an executable
1: #!/usr/bin/env bash
2:
3: # Get the git branch / tag name
4:
5: # first, see of we have branch information (this will not be available if we checked out a tag)
6: TAG_OR_BRANCH="$(git rev-parse --abbrev-ref HEAD | egrep -o '([0-9]{1,}\.)+[0-9]{1,}')"
7:
8: if [ "$TAG_OR_BRANCH" == "" ]; then
9:
10: # if we can't get branch info, then we must be in a tag, so use that
11: TAG_OR_BRANCH="$(git describe | egrep -o '([0-9]{1,}\.)+[0-9]{1,}+(-b[0-9]{1,})')"
12: fi
13:
14: # Remove the version from the properties file
15: sed -i '/^version=/ d' src/main/resources/static/version
16:
17: # Add the version to the properties file
18: echo "Writing version $TAG_OR_BRANCH"
19: echo "version=$TAG_OR_BRANCH" >> src/main/resources/static/version