[Maven + Git] Releasing and Branching done right…
Maven is really awful. I hate it.
But it is by far the best tool available… Therefore I am using it for several years now. And since it is a tool one has to struggle with, I have invested a lot of time into optimizing my build environment. So I know Maven quite well now – better than I wanted…
And of course I am using Git. And I really love it. But unfortunately Git is just a second class citizen in Maven land. The basic things work, but other things don’t (like mvn release:branch).
I have created this checklist for doing a release. Just take a look and compare it with the steps you are doing. I’d like to hear some opinions and ideas for improvements.
I use some scripts that make my life easier:
The version numbers
The upcoming release will be 1.0.0 (the first release for this project). Therefore no maintenance branches exist yet.
Currently the master branch is set to 1.0.0-SNAPSHOT.
|master||Contains the current development version (that will be released as next major release).
(I have an additional pu branch that is merged to master automatically when all tests have been run successfully, but that doesn’t matter for this entry)
|next||Contains some experimental code (that will be merged to master one day)|
|maint-[VERSION]||Maintenance branches for every version. Just bugfixes are commited here and merged up.|
Release: What has to be done
The master branch contains the latest peace of software that shall be released (that means that all bugfixes have been merged in from the maint* branches).
- Tag for the release
- Creating a new maint-* branch with updated version number
- Updating the version number for master
- Probably updated the version number for next, too
And: Of course release one version of our software…
1: Ensure all bugfixes have been merged into master
git log master..maint-[VERSION]
2: Creating the maint-branch
git checkout master git checkout -b maint-1.0.0 git publish-branch
3: Releasing on maint
mvn release:prepare mvn release:perform
4: Merging maint to master
git checkout master git merge maint-1.0.0
5: Updating the version on master
mvn versions:set -DnewVersion=1.1.0-SNAPSHOT -DgenerateBackupPoms=false git commit -a -m "preparing for next major release: updated version in master"
6: Merging master to next
git checkout next git merge master
That merge has probably one merge conflict: The version in the pom.xml. Just keep the value of the next branch.
7: Updating the version for next (optional/if necessary)
mvn versions:set -DnewVersion=2.0.0-SNAPSHOT -DgenerateBackupPoms=false git commit -a -m "preparing release: updated version in next"
8: Pushing the changes
Now there are three branches with different version numbers: