Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven-buildnumber-plugin svn revision available only when not using format

While using the maven-buildnumber-plugin 1.0 beta 4, it seems that I can get the svn revision unless I use a <format> tag within the configuration. Once I use <format> and <item>buildnumber</item> tag, I get an auto-incrementing number, but it no longer corresponds to svn revision and I don't know how to get it back. Is there a way to use the svn revision number within the <format>? The documentation isn't very clear.

like image 817
gtrak Avatar asked Nov 30 '10 22:11

gtrak


1 Answers

The buildnumber-maven-plugin is pretty darn quirky, which is probably why it's still a beta. The format is only for those items you wish to apply a Java message format to and in most cases, it only useful with timestamps and literal strings. If you don't need a timestamp don't use the format option when getting the Subversion revision number. If you use the format, then like you indicated, it'll give you a build number that always increments by one rather than the SCM version number.

If you do need the timestamp or have other items your deriving from the buildnumber plugin as well as the Subversion revision, do each one as a separate executions. Here's an example of how to get the Subverison revision number and the build timestamp using two separate executions of the plugin:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>buildnumber-maven-plugin</artifactId>
    <version>1.0-beta-4</version>
    <executions>
        <execution>
            <id>generate-buildnumber</id>
                <phase>validate</phase>
            <goals>
                <goal>create</goal>
            </goals>
            <configuration>
                <useLastCommittedRevision>true</useLastCommittedRevision>
                <buildNumberPropertyName>buildRevision</buildNumberPropertyName>
            </configuration>
        </execution>
        <execution>
            <id>generate-timestamp</id>
            <phase>validate</phase>
            <goals>
                <goal>create</goal>
            </goals>
            <configuration>
                <format>{0,date,yyyy-MM-dd HH:mm:ss}</format>
                <items>
                    <item>timestamp</item>
                </items>
                <buildNumberPropertyName>buildDateTime</buildNumberPropertyName>
            </configuration>
        </execution>
    </executions>
</plugin>

The key to making this work is using the buildNumberPropertyName element. Checkout the plugin's Usage page for more information about the usefulness of the Java message format is for.

like image 95
jgifford25 Avatar answered Sep 21 '22 17:09

jgifford25