cdavid15
cdavid15

Reputation: 453

Specifying the Date in the tag generated by the maven-release-plugin

Within our project we declare our SVN tags in the format:

YYYY-MM-DD - v{project.version} [${environment}]

eg 2012-01-16 - v1.0.1 [LIVE]

Is it possible to achieve this with the maven-release plugin (version 2.2.2)?

It worth pointing out that the version and the environment parts are obtained and work with the release plugin. It is purely the timestamp that can't be retrieved.

This is what I would expect would work:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-release-plugin</artifactId>
    <version>2.2.2</version>
    <configuration>
        <preparationGoals>clean verify</preparationGoals>
        <tagNameFormat>${timestamp} - v@{project.version} [${env}]</tagNameFormat>
        <checkModificationExcludes>
          .
          .
          .    
        </checkModificationExcludes>
    </configuration>
</plugin>

The timestamp property is generated successfully using the buildnumber-maven-plugin as it is added to the manifest file for inclusion to the war file.

I have tried adding buildnumber:create goal into the preparation goals but it produces the following output when executing the release:prepare

What is SCM release tag or label for "Project Name"? (a.b.c.d) null - v1.0.1 [LIVE]: :

The issue seems to be that the the timestamp property is not generated at the point the tagName is being set which indicates that the preparation goals are not performed at the stage is asks for the tagName.

The following might work (will test it after lunch) although it i'd much rather just call release:prepare

mvn buildnumber:create release:prepare

Any input would be welcomed.

Cheers


EDIT

I have tested using the buildnumber:create release:prepare and it does work as expected although I did have to make further modifications which to be honest is a bit of a pain.

The TagNameFormat currently contains:

YYYY-MM-DD - v{project.version} [${environment}]

This contains spaces and square brackets and upon executing with this format you will get a error indicating the URL is not properly URI encoded. To get round this you must specify the tagNameFormat in a format that is already URI Encoded such as:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-release-plugin</artifactId>
    <version>2.2.2</version>
    <configuration>
        <preparationGoals>clean verify</preparationGoals>
        <tagNameFormat>${timestamp}%20-%20v@{project.version}%20%5B${env}%5D</tagNameFormat>
        <checkModificationExcludes>
          .
          .
          .    
        </checkModificationExcludes>
    </configuration>
</plugin>

This is nasty but it does work and it will create the tag as required.

Would be still interested to see if anyone has any suggestions as to how to get the timestamp in the tagNameFormat by just executing:

mvn release:prepare

and not

mvn buildnumber:create release:prepare

Upvotes: 4

Views: 2842

Answers (1)

wemu
wemu

Reputation: 8160

As of Maven 2.1 there is a variable: maven.build.timestamp available which can be configured using a property:

<properties>
  <maven.build.timestamp.format>yyyyMMdd-HHmm</maven.build.timestamp.format>
</properties>

See: http://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Available_Variables

This might make the buildnumber plugin no longer required and should be simpler to use.

Upvotes: 4

Related Questions