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.

4 comments:

asdf 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.

sandeep saxena said...

it is a useful article when i compared to others.thanks for this wonderful article and im really happy to read this.
DevOps certification in Chennai
DevOps Training in Chennai
DevOps course in Chennai
Data science course in chennai
AWS training in chennai
AWS certification in chennai

Aishwariya said...

Awesome post.Really nice blog, i enjoyed your infomations. Thank you and i will expect more in future..keep it up!!
Amazon Web Services Training in Chennai

Meri said...

yurtdışı kargo
resimli magnet
instagram takipçi satın al
yurtdışı kargo
sms onay
dijital kartvizit
dijital kartvizit
https://nobetci-eczane.org/
VMXİA

Post a Comment