How to set tag for Maven release

10,934

Your pom is probably on version 1.3-SNAPSHOT

mvn release:prepare

Will update the version to 1.3, create the git tag "artifactid-version" in your case my-project-1.3, then set the version in your pom to 1.4-SNAPSHOT for the next iteration.

To fix your problem delete the tag see How to delete a git remote tag? then run mvn release:prepare again.

You may need to set your version back to 1.3-SNAPSHOT, this can be done with

mvn versions:set -DnewVersion=1.3-SNAPSHOT

Or just edit you pom/poms.

Share:
10,934
bsky
Author by

bsky

Updated on December 02, 2022

Comments

  • bsky
    bsky over 1 year

    I'm using the Maven Release Plugin and I'm trying to tag every release with my Jenkins build number.

    I've tried this from pom.xml:

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <version>2.5.3</version>
            <configuration>
              <tagNameFormat>${env.BUILD_NUMBER}</tagNameFormat>
            </configuration>
          </plugin>
    

    And also from Jenkins when I'm calling Maven:

    mvn release:prepare -tag=${env.BUILD_NUMBER}
    

    However, I'm getting:

    Unable to tag SCM
    [ERROR] Provider message:
    [ERROR] The git-tag command failed.
    [ERROR] Command output:
    [ERROR] fatal: tag 'my-project-1.3' already exists
    

    I'm not sure what 1.3 stands for.

    So how can I tag the release? I am doing any mistake?

  • bsky
    bsky about 7 years
    If I do mvn release:prepare multiple times, the version still remains 1.3 and isn't incremented. Any idea why?
  • Essex Boy
    Essex Boy about 7 years
    @octavian The version will be changed to 1.4-SNAPSHOT after the git tag, so it that command fails this will not happen.
  • bsky
    bsky about 7 years
    Can I do something like mvn release:prepare -DnewVersion=${env.BUILD_NUMBER}, where BUILD_NUMBER is the build number from Jenkins? I would like to specify a version depending on the Jenkins build number but I don't know how.
  • Essex Boy
    Essex Boy about 7 years
    @octavian you are getting away from the idea of a "release" in maven terms. A release is intended to be done rarely, say at the end of a sprint, The version should be decided by the project. Perhaps you don't really want to do a release? Remember you still have all you git commits which you can go back to if needed. HTH.
  • bsky
    bsky about 7 years
    In the end, I will not do a release for every build. I will do a release only in some cases. However, I would like to have the build number in the name as well.
  • Essex Boy
    Essex Boy about 7 years
    @octavian mvn:release:prepare will tag and update the version, mvn release:perform will install the released/tagged version in your repository (Nexus or similar). This is then an immutable binary artifact which is linked to a source code state by the git tag. Why do you need the build number? You can return the the source with a simple "git checkout my-project-1.3"