0
votes

Configuration Management team at my workplace mandates 4 digit version numbers for artefacts - say, 1.2.3.4 - for released artefact and 1.2.3.5-SNAPSHOT for development pom

In addition to this, our version control system (clearcase) has pre-label trigger which enforces a certain naming convention for label/tag.

So, if the pom version is 1.2.3.4-SNAPSHOT and artifactId is, for instance, shopcart then, as per the tag naming requirement, tag name should be:

XXX_1.2.3_SHOPCART_DROP4_SRC

where XXX is project code - constant string value.

As you see, in order to achieve this format, I need to make following customisations to tag name format:

  • artifactId - convert to uppercase
  • first 3 digits of 4 digit version number to be extracted
  • last digit of 4 digit version number to be extracted
  • concatenate everything as per the format.

I thought I would use gmaven plugin to get this done and populate a custom property to be used in tag or tagNameFormat configuration property of maven release plugin (v2.3.2) - but that doesn't work at all.

maven release plugin supports only 3 properties (artifactId, version, groupId) and doesn't support any other property.

gmaven plugin works as expected and sets a final user property in the tag name format I need - I verified it using the ant run maven plugin to echo the property.

Problem is with maven release plugin - it doesn't understand any user property...

Can anyone help how can I achieve this?

EDIT:

Interactive run is not a possibility - need to configure this to run for about 15 projects on jenkins ...

Many thanks, Tapasvi

1

1 Answers

0
votes

You should read the documentation of the maven-release-plugin carefully cause there is a parameter which can be used for such purposes. The tagNameFormat which can be used to change the format of the tag which will be created (Oh sorry. You already read that). The version can extract into properties via the buildhelper-maven-plugin. Furthermore the buildhelper-maven-plugin can be used to make uppercase of the artifact id:

Set a property by applying a regex replacement to a value

The regex-property goal can be used to set a property to a value after regex replacement has been applied. For example, executing the following plugin configuration to set the clearcase.artifact property.

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.7</version>
        <executions>
          <execution>
            <id>regex-property</id>
            <goals>
              <goal>regex-property</goal>
            </goals>
            <configuration>
              <name>clearcase.artifactid</name>
              <value>$\{project.artifactId}</value>
              <regex>(.*)</regex>
              <replacement>???</replacement>
              <failIfNoMatch>false</failIfNoMatch>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  ...
</project>

But you need to be carefull about setting properties, cause release:perform fork a Maven process. You might need to use the -Darguments option to set the appropriate parameters.