How to add a version number to your hudson-built maven jar

Maven’s jar plugin will automatically add a “pom.properties” in your jar’s META-INF/maven/$groupId/$artifactId directory. If you build with hudson, there are a number of other values that you might want to include automatically, though, like the SVN revision number that the artifact was built from, and when it was built.

Here’s the configuration for the maven-jar-plugin that adds a couple of the more-interesting hudson variables to your module’s jar’s META-INF/MANIFEST.MF:

[xml highlight="12,13,14,15"]
<project>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<configuration>
<archive>
<manifestEntries>
<Svn-Revision>${SVN_REVISION}</Svn-Revision>
<Build-Tag>${BUILD_TAG}</Build-Tag>
<Build-Number>${BUILD_NUMBER}</Build-Number>
<Build-Id>${BUILD_ID}</Build-Id>
</manifestEntries>
</archive>
</configuration>
</plugin>

[/xml]

The Maven Guide to Working with Manifests and Maven Archiver pages, along with the other hudson variables may prove helpful.

Update December 14, 2009:

Note that Hudson’s SVN_REVISION macro is empty if you build your project as a maven multi-module.

Related posts:

  1. How to add a version number to your maven webapp
    I couldn’t find a simple recipe to add a version number to a maven-built webapp. The maven-war-plugin talks about how to filter, but no simple example is given. So. I’ll......
  2. How to increase maven heapspace in hudson builds
    If your maven-built project fails in hudson (especially when you’re using the assembly plugin) and it isn’t a compile or test failure, check the console output. If it says “java.lang.OutOfMemoryError:......
  3. How to set up your Maven2 POM to support Java5
    Seeing this? [bash highlight="3,4"] $ mvn compile … generics are not supported in -source 1.3 (try -source 1.5 to enable generics) [/bash] You need to tell the maven-compiler-plugin to use......
  4. Getting started with Hudson
    Hudson is a slick, stable, and easy to install continuous integration environment. You’ll be using it in minutes. Honest. Install Java Hudson is a java webapp. Ubuntu comes with Sun’s......

This entry was posted in Technical HOWTOs and tagged , . Bookmark the permalink.

2 Responses to How to add a version number to your hudson-built maven jar

  1. Trenton says:

    And to see your handiwork:

    % unzip -p mymodule-1.0-SNAPSHOT.jar META-INF/MANIFEST.MF

    Manifest-Version: 1.0
    Archiver-Version: Plexus Archiver
    Created-By: Apache Maven
    Built-By: hudson
    Build-Jdk: 1.5.0_18
    Build-Id: 2009-07-27_14-57-00
    Build-Number: 16
    Build-Tag: hudson-mymodule-16
    Hudson-Build-Number: 16
    Hudson-Project: mymodule
    Hudson-Version: 1.316
    Svn-Revision: 47689

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Additional comments powered by BackType