3

When executing the mvn release:branch command, I'd like to try and configure the -DbranchName argument with a version parameter. But I haven't been able to find a way to successfully do this yet.

For example, if I have a project in trunk with version 1.0-SNAPSHOT, I want to create a branch using the --batch-mode option and specify a -DbranchName with the current project version (1.0-SNAPSHOT) as a parameter in the within the branchName.

I've tried doing mvn release:branch -DbranchName=VERSION-@{project.version}, but it doesn't seem to work as I had hoped. Instead of creating a branch with the name VERSION-1.0, I get the following error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.3:branch (default-cli) on project project-a: Unable to branch SCM
[ERROR] Provider message:
[ERROR] The svn branch command failed.
[ERROR] Command output:
[ERROR] svn: E205000: Try 'svn help copy' for more information
[ERROR] svn: E205000: Syntax error parsing peg revision '{project.version}'

Is there a valid way to do this? Or is this not possible when doing a release:branch with the maven release plugin?

Edit

Basically what I'm looking for is something similar to the tagNameFormat property but for branches. When doing a release:perform goal, I can have <tagNameFormat>VERSION-@{project.version}</tagNameFormat> specified in the pom, and I don't need to include any tag name property when doing a release using --batch-mode. Is there any similar property for formatting of branch names when doing a release:branch?

Josh
  • 33
  • 5

1 Answers1

5

You can use the built-in ${project.version} (prefixed with $ instead of @ -- the latter seems only available in the tagNameFormat parameter). Note that if you use ${project.version}, the value will probably contain the substring SNAPSHOT in it. There may be several ways of removing that substring. One way is to apply the helper plugin mentioned in the answer to this question which gives you access to the version's semantic components:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.8</version>
    <executions>
      <execution>
        <id>parse-version</id>
        <goals>
          <goal>parse-version</goal>
        </goals>
      </execution>
    </executions>
</plugin>

Then you can use the properties on the command line:

mvn release:branch -DbranchName=VERSION-${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}

Or better to include the branchName parameter as part of the plugin configuration:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-release-plugin</artifactId>
    <version>2.5.3</version>
    <executions>
        <execution>
            <configuration>
                <branchName>VERSION-${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}</branchName>
            </configuration>
            <goals>
                <goal>branch</goal>
            </goals>
        </execution>
    </executions>
</plugin>

In this case you don't need to pass these magic properties on the command line.

Community
  • 1
  • 1
M A
  • 71,713
  • 13
  • 134
  • 174