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 build.properties file I use for the build.


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



Here is the contents of the build-info.properties file:
#This file is automatically generated - DO NOT EDIT
#Sun Aug 15 17:04:03 CEST 2010
Build-Version=0.1-b15
Built-By=tim

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

No comments: