Using SVN revision as software version via Ant

I use Subversion for my personal projects and web sites and for one of my projects I wanted to use the SVN revision value as the version number for the project. As it's a Java based project and I'm using an Ant script to package & deploy it I wanted to retrieve the repository revision in the Ant script and automatically set the version value in the configuration file. After a bit of searching I found this article on how to get the revision value via Ant, all it requires is that the command line version of Subversion is installed.

So I added the following target to my Ant script to retrieve the last changed revision (slightly modified from the original):

<target name="svnrevision">
	<exec executable="svnversion" outputproperty="repository.revision">
		<arg value="-c" />
					<replaceregex pattern="[0-9]+\:" replace="" />
					<replaceregex pattern="[M]" replace="" />
        <echo message="Current revision is ${repository.revision}" />

Then later on in my Ant script I use the extracted variable to set the version value in the file while copying it:

<copy file="./src/" tofile="./deploy/">
		<filter token="version" value="${repository.revision}" />

The file simply has the following line in it:


And that's it.