Wednesday, February 06, 2008

How to Auto Increment version (build id) with Ant

For those who are still stuck with manual ant builds, this tiny little tip will tell you how to auto increment the version number with each Ant build. Follow the steps:

1. Create a file say build.number (or change the name to one which gives you pride)
2. Add the following target to your build.xml file, change entry key to whatever you want the property name to be:
<target name="increment_teh_build_number">
<propertyfile file="build.number"
comment="Build Number for ANT. Edit not!">

<entry key="build.number" type="int"
operation=
"+"
default=
"1" />

</propertyfile>
</target>
3. Make sure this target is executed on successful build for example after 'test' target, Once this target is executed you can use property build.number where-ever you like in build.xml, For example,

<property name="app.version" value="${major.minor}.${build.number}" />

Hope that saves you some.

4 comments:

KetanPadegaonkar said...

I generally just use the svn version number for numbering builds.

If you look at http://swtbot.svn.sourceforge.net/svnroot/swtbot/trunk/net.sf.swtbot.build/build.xml, and a few properties below the beanshell, you'll see that I just pull out the svn revision number and use that to number a particular build.

Nirav Thaker said...

That's good tip too. Although I can't use it out of the box though, I have to use CVS.

Michaes said...
This comment has been removed by the author.
Michaes said...

Thanks for the post. I guess you need to add

property file="build.number.properties"

before start using ${build.number}