18

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?

Betlista
  • 10,327
  • 13
  • 69
  • 110
Andrew Swan
  • 13,427
  • 22
  • 69
  • 98
  • See [my comment](http://stackoverflow.com/questions/4466714/how-to-customise-the-tag-format-of-the-maven-release-plugin#comment21031508_13886493) below. This behaviour is broken again in v2.4. In fact, v2.1 of the release plugin is the only one currently working properly. – Duncan Jones Feb 20 '13 at 10:39

3 Answers3

20

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>

Note that, in order to ensure that the interpolation occurs during release, you must use @{...} to reference the properties rather than ${...}.

not2savvy
  • 2,902
  • 3
  • 22
  • 37
Lyle
  • 3,724
  • 3
  • 25
  • 25
  • 1
    Please note that **v2.1** is the latest version in which this behaviour works correctly. Since that release, the code base is broken and the `-SNAPSHOT` version is used. See [this bug](http://jira.codehaus.org/browse/MRELEASE-695) for further info. – Duncan Jones Feb 20 '13 at 10:39
  • 2
    Note the at-sign in @{project.version} is important. The similar looking ${project.version} just gets the version from the pom.xml. I don't the significance of $ and @? – Josh Jul 19 '13 at 16:50
  • I just used **v2.5.3** and a it correctly tagged using just the project version using a configuration of: `@{project.version}` – Matthew Buckett Mar 16 '19 at 08:07
3

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)
Andrew Swan
  • 13,427
  • 22
  • 69
  • 98
  • 2
    MRELEASE-159 has been marked as fixed in 2.2, and the other two tickets are marked as duplicates of it. I no longer use SVN, but I've changed the accepted answer to Lyle's, which documents the new tagNameFormat option. – Andrew Swan Dec 17 '12 at 09:00
1

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

<tag>${project.artifactId}/${releaseVersion}</tag>
Betlista
  • 10,327
  • 13
  • 69
  • 110