Saturday, November 28, 2009

buildnumber-maven-plugin helpful improvements

I've used the buildnumber-maven-plugin to include revision ids and timestamps in my builds for many years. Today I upgraded to the most recent version and that helped get rid of a few workarounds I had in place.

Using a previous version of the plugin, if there was no svn on your path, or your project was not checked in yet to subversion, the plugin failed the build due to svn checks. The workaround I had was to add it to a profile that only got executed when .svn file existed and/or the useReleaseProfile property was 'true'.

Now I am relieved to see I don't need to do that anymore.

For one, there is a 'revisionOnScmFailure' property you can set in the configuration that will be used if there is any type of scm exception - a byproduct of which disables further scm communication.

Second you can specify the plugin to use the javasvn scm provider implementation in case there is no 'svn' executable on your PATH. At first pass it might seem unlikely that when dealing with a subversion based project a developer would not have svn on the path, and that is likely true. Consider though that the svn version may be wrong (in which case svn may complain about not being new enough and fail the build) or you are building in a continuous integration env like hudson and you want reproducible use of the same svn tool. In those cases it makes good sense to configure the plugin with "javasvn". See below example:

<plugin>
  <groupid>org.codehaus.mojo</groupid>
  <artifactid>buildnumber-maven-plugin</artifactid>
  <version>1.0-beta-4</version>
  <configuration>
    <revisiononscmfailure>UNKNOWN_REVISION</revisiononscmfailure>
    <providerimplementations>
      <svn>javasvn</svn>
    </providerimplementations>
  </configuration>
  <executions>
    <execution>
      <id>buildnumber-one</id>
      <phase>validate</phase>
      <goals>
        <goal>create</goal>
      </goals>
    </execution>
    <execution>
      <id>buildnumber-two</id>
      <phase>validate</phase>
      <goals>
        <goal>create</goal>
      </goals>
      <configuration>
        <format>r${buildNumber} {0,date,yyyy-MM-dd'T'HH:mm:ss.SSSZ}</format>
        <items>
          <item>timestamp</item>
        </items> 
      </configuration>
    </execution>
  </executions>
</plugin>

The two executions is so that I can give some context to the ${buildNumber} by prefixing it with 'r' and adding a timestamp formatted along with it.

There are a bunch of other useful properties in this latest release. Thanks to open source.

1 comment:

Tom Saleeba said...

Thanks mate, this did the trick for me. I didn't know you could do multiple executions of one plugin either so that's a cool trick to know. Cheers.

Post a Comment