We also have the same convention, but we use git: in the main branch, our version of maven is always 0.0.1-SNAPSHOT, and for each branch, maven is the BRANCH_NAME-SNAPSHOT branch.
We solved the same merge from the branch to the main problem, and, in addition, the developers forgot to run versions:set and commit the wrong version in the main.
We created a git hook that prevents such incorrect commits:
#!/bin/bash # To enable this hook: # ln -s ~/src/common-arsbigdata/common-fw/src/main/resources/bin/pre-commit ~/src/common-arsbigdata/.git/hooks/pre-commit BRANCH_NAME=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') echo "current branch: $BRANCH_NAME" for file in $(find . -name 'pom.xml' -not -path "*/target/*" -not -path "*/bin/*"); do VERSION=`head $file | grep "<version>" | sed -e 's,.*<version>\([^<]*\)-SNAPSHOT</version>.*,\1,g'`; if [[ $BRANCH_NAME == "master" ]]; then if [[ $VERSION != "0.0.1" ]]; then echo $file echo "expected version 0.0.1, actual version is $VERSION" exit 1 fi elif [[ $VERSION != $BRANCH_NAME ]]; then echo $file echo "expected version $BRANCH_NAME, actual version is $VERSION" exit 1 fi done
We control the hook inside the git repository and create a soft link in .git/hooks for it on each dev machine
source share