Kennis Blogs Maven release plugin setup guide for Git

Maven release plugin setup guide for Git

The Maven Release Plugin is really effective and easy to use. The initial configuration, however, can be a bit of a pain, especially because Git support is rather minimal. Here are a few tips that might help you get going...

 

The first step is to setup the Release Plugin in your POM. Make sure to use the following tags in your pom.xml file:

  • <scm> tag with source control system url in <developerConnection>
  • <version> tag with SNAPSHOT version
  • <distributionManagement> tag with repository url

 

Normally this should work. A mvn release:prepare should now exit successfully. But unfortunately, it won't if you use Git.

 

Maven automatically downloads the latest version of the release plugin. But this doesn't work when using Git. Also, if you have your Git repo organized with multiple Maven projects in one repository, know that the Maven Release Plugin will not work out of the box.

 

Luckily there is an easy fix. Just configure the maven plugin in your pom.xml as follows:

<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>default</id>
<goals>
<goal>perform</goal>
</goals>
<configuration>
<pomFileName><your_project>/pom.xml</pomFileName>
</configuration>
</execution>
</executions>
</plugin>
...
</plugins>
</build>

 

Now commit your project first and push it to the master branch before testing. Your release should now run succesfully!