Skip to content

Instantly share code, notes, and snippets.

@ssledz
Forked from nwinkler/pom.xml
Created January 29, 2017 02:19
Show Gist options
  • Save ssledz/74036fa9b3d93e53d8737f5658d46c92 to your computer and use it in GitHub Desktop.
Save ssledz/74036fa9b3d93e53d8737f5658d46c92 to your computer and use it in GitHub Desktop.
Combining the git-flow branching model and the Maven Release Plugin to play nice. Based on info found here: http://vincent.demeester.fr/2012/07/maven-release-gitflow/
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>group</groupId>
<artifactId>dummy</artifactId>
<name>Dummy Project</name>
<version>1.0.12</version>
<packaging>pom</packaging>
<scm>
<connection>scm:git:https://......</connection>
<tag>HEAD</tag>
</scm>
<build>
<plugins>
...
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<!-- Keep changes in the local repo, push will be done afterwards -->
<pushChanges>false</pushChanges>
<localCheckout>true</localCheckout>
<!-- Use a better name for the tag -->
<tagNameFormat>v@{project.version}</tagNameFormat>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-provider-gitexe</artifactId>
<version>1.9</version>
</dependency>
</dependencies>
</plugin>
...
</plugins>
</build>
</project>
#!/bin/bash
# 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: http://vincent.demeester.fr/2012/07/maven-release-gitflow/
# CHANGE THESE BEFORE RUNNING THE SCRIPT!
# The version to be released
releaseVersion=1.0.11
# The next development version
developmentVersion=1.0.12-SNAPSHOT
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment