Creating a Build Number With Ant and Subversion
I’m on a hot streak tonight… Another comon problem that I have had to solve recently is how to attach a build number to files that are being generated out of an Ant build script.
We have developed a versioning scheme (inspired by http://geekswithblogs.net/emanish/archive/2006/09/25/92219.aspx) for our releases where our release are named
There are a few ways to do this, One way that I considered was to just include a property or Subversion tag in the build.properties file. But I did not want to maintain it and I have always loathed the auto tags that were available in CVS.
My second option was to use the
So, I decided to go with using the task in conjunction with svn info and svnversion to set the full.build.version property to the current release number. This assumes that the repository checked out is of the format svn://REPO_NAME/tags/
I’m sure that I could have gotten the revision from the svn info rather than svnversion, saving a command, but I wasn’t inspired enough to do it. Maybe when I have more time.
<exec outputproperty="build.current.revision" executable="svnversion">
<arg line="-n -c" />
<redirector>
<outputfilterchain>
<tokenfilter>
<replaceregex pattern="^[0-9]*:?" replace="" flags="g"/>
</tokenfilter>
</outputfilterchain>
</redirector>
</exec>
<exec outputproperty="build.current.version" executable="svn">
<arg line="info" />
<redirector>
<outputfilterchain>
<linecontainsregexp><regexp pattern="^URL:" /></linecontainsregexp>
<tokenfilter>
<replaceregex pattern=".*\/([^\/]+)$" replace="\1" flags="g"/>
</tokenfilter>
</outputfilterchain>
</redirector>
</exec>
<property name="full.build.version" value="${build.current.version}.${build.current.revision}" />