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 succesfully. 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!

  • Facebook
  • LinkedIn

7 thoughts on “Maven release plugin setup guide for Git

  1. Isn’t this very much an issue of how you organized the project in your Git repo? If you place the pom.xml in the root of the repo your shouldn’t have an issue right? I’m not saying that’s the way to do it though, having one repo with multiple Maven modules sounds fine.

  2. If you have your pom in the root of your Git repo, you probably have no issues. But it’s not only the structure of the Git repo. Also with multi module projects you can run into this issue when you want to release only one module.

  3. The error you get from Maven when your pom.xml is in a subdirectory of the git repository is:

    [INFO] [ERROR] The goal you specified requires a project to execute but there is no POM in this directory

    This is resolved by specifying the location in the release plugin, as described in this post.

  4. I set to the pom.xml’s relative path in the Git repository.
    Is this correct?
    But unfortunately I still got the same error:
    [INFO] [ERROR] The goal you specified requires a project to execute but there is no POM in this directory

    • Agnes on March 7, 2012 at 11:15 said:
      Your comment is awaiting moderation.

      I set [your_project] to the pom.xml’s relative path of the Git repository.
      But unfortunately I still got the same error:
      How do you set [your_project]? Thanks.

    • Hi Agnes,

      Yes, you need to set the option in the release plugin configuration with the relative path to your pom file. That is relative to your git repository root.
      This seems to only work for plugin version 2.2.1 or higher. Do you use the correct version?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>