Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 963
Andrew Swan Avatar asked Dec 17 '10 00:12

Andrew Swan


People also ask

What is Maven release plugin?

This plugin is used to release a project with Maven, saving a lot of repetitive, manual work. Releasing a project is made in two steps: prepare and perform. Note: Maven 3 users are encouraged to use at least Maven-3.0. 4 due to some settings related issues.

What is mvn release prepare?

mvn release:prepareThis command prepares for a release in SCM. It goes through several phases to ensure the POM is ready to be released and then creates a tag in SVN which can be used by release:perform to make a release.

What is the use of SCM tag in POM xml?

Assuming that SCM has been configured in the pom. xml and the project directory is managed by a SCM, invoking the checkin goal in the scm will start the commit process for all configured sources in your pom. xml . The files should be added beforehand by an external scm client.


2 Answers

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>
like image 149
Lyle Avatar answered Nov 16 '22 00:11

Lyle


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)
like image 23
Andrew Swan Avatar answered Nov 16 '22 02:11

Andrew Swan