Skip to content

Instantly share code, notes, and snippets.

@nwinkler nwinkler/pom.xml
Last active Mar 31, 2020

What would you like to do?
Combining the git-flow branching model and the Maven Release Plugin to play nice. Based on info found here:
<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">
<name>Dummy Project</name>
<!-- Keep changes in the local repo, push will be done afterwards -->
<!-- Use a better name for the tag -->
# THe issue is that the Maven Release Plugin insists on creating a tag, and git-flow also wants to create a tag.
# Secondly, the Maven Release Plugin updates the version number to the next SNAPSHOT release before you can
# merge the changes into master, so you end with the SNAPSHOT version number in master, and this is highly undesired.
# This script solves this by doing changes locally, only pushing at the end.
# All git commands are fully automated, without requiring any user input.
# See the required configuration options for the Maven Release Plugin to avoid unwanted pushs.
# Based on the excellent information found here:
# The version to be released
# The next development version
# Provide an optional comment prefix, e.g. for your bug tracking system
scmCommentPrefix='GST-1234: '
# Start the release by creating a new release branch
git checkout -b release/$releaseVersion develop
# The Maven release
mvn --batch-mode release:prepare release:perform -DscmCommentPrefix="$scmCommentPrefix" -DreleaseVersion=$releaseVersion -DdevelopmentVersion=$developmentVersion
# Clean up and finish
# get back to the develop branch
git checkout develop
# merge the version back into develop
git merge --no-ff -m "$scmCommentPrefix Merge release/$releaseVersion into develop" release/$releaseVersion
# go to the master branch
git checkout master
# merge the version back into master but use the tagged version instead of the release/$releaseVersion HEAD
git merge --no-ff -m "$scmCommentPrefix Merge previous version into master to avoid the increased version number" release/$releaseVersion~1
# Removing the release branch
git branch -D release/$releaseVersion
# Get back on the develop branch
git checkout develop
# Finally push everything
git push --all && git push --tags

This comment has been minimized.

Copy link

cpfabian23 commented Oct 28, 2015

Nice work man!
The only thing here I don't get clear is this:
When you create a release branch, you are supposed to test and validate it before close it, and probably you will have to add fixes to it so you can re-deploy it to QA for more testing. Finally when it is approved, then you can deploy to production, therefore you can merge it to master and develop accordingly.
So, in this case, you are not giving the time to do the testing, just creating and deleting it at the same time.
I am interested in how you manage your projects using this kind of scripts for releases. Do you use master branch for QA and Production?

Thanks! Really useful.


This comment has been minimized.

Copy link

qoomon commented Oct 16, 2017
This extension generate the version by the current branch. It will not change the pom.xml so.
Disclaimer: I am the author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.