Sunday, August 15, 2010

Java Ant - Build .War file with Auto-Incrementing Build Number

To auto-increment a build number while building a .war file with ANT, we can create a .properties file using the propertyfile ant task in combination with the buildnumber ant task. The buildnumber task creates a build.version file and increments the build number contained within during each build. The following task in my Ant build file creates a properties file with auto-incrementing build information along with the person who built the .war file and a timestamp. The ${major.minor.version} variable comes out of a file I use for the build.

<target name="buildinfo">   
    <buildnumber />
    <propertyfile file="${build.dir}/"
        comment="This file is automatically generated - DO NOT EDIT">
        <entry key="Built-By" value="${}"/>
        <entry key="Build-Version" value="${major.minor.version}-b${build.number}"/>

Here is the contents of the file:
#This file is automatically generated - DO NOT EDIT
#Sun Aug 15 17:04:03 CEST 2010

See also:
Hello World Java Web Application in Eclipse (Part 3)

No comments: