How to customise the tag format of the Maven release plugin?

10,959

Solution 1

The release plugin now supports the tagNameFormat configuration option, which defaults to @{project.artifactId}-@{project.version}. In your case, you could do something like:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-release-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <tagNameFormat>@{project.artifactId}/@{project.version}</tagNameFormat>
    </configuration>
</plugin>

Solution 2

It looks like this is not possible until one of these bugs is fixed:

  • MRELEASE-150: Can't add prefix to tags without affecting version (not scheduled)
  • MRELEASE-159: Support a pattern to generate the release tag (scheduled for 2.2)
  • MRELEASE-259: Provide a configuration settings for default tag/label to use when releasing (not scheduled)

Solution 3

If you are passing in the releaseVersion, you can do this:

<tag>${project.artifactId}/${releaseVersion}</tag>
Share:
10,959
juckele
Author by

juckele

Senior developer on the JIRA team with Atlassian.

Updated on June 02, 2022

Comments

  • juckele
    juckele about 2 years

    In our SVN repo, we store tags like this:

    trunk
        project_a
        project_b
    branches
        project_a
            branch_x
            branch_y
        project_b
    tags
        project_a
            1.0
            1.1
        project_b
            1.0
    

    When I run the Maven release plugin's "prepare" goal on project A, by default it creates the tag as "tags/project_a-x.x", which does not match my tag naming scheme above. I am thus depending upon whoever does the release (i.e. a fallible human) to spot this and change the tag to "tags/project_a/x.x". How can I tell the release plugin to use the correct format by default?

    The "prepare" goal has a "tag" configuration option that claims to do this, but if I set it as follows:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-release-plugin</artifactId>
        <version>2.1</version>
        <configuration>
            <tag>${project.artifactId}/${project.version}</tag>
        </configuration>
    </plugin>
    

    ... then the created tag is "tags/project_a/x.x-SNAPSHOT", i.e. it uses the pre-release version number instead of the release version number. Hardcoding the tag name into the POM seems wrong too.

    How can I ensure that the tag is correct by default?