How to customise the tag format of the Maven relea

2019-04-05 02:22发布

问题:

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?

回答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>


回答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)


回答3:

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

<tag>${project.artifactId}/${releaseVersion}</tag>