Getting Subversion Revision in Ant – Part II


[tweetmeme source=”gosub3000”]
We have previously discussed getting the subversion revision number from an ant script.  While the previous method relied on antcontrib and regexes, I’ve recently come across the SvnAnt project.

SvnAnt is a contribution for ant, which allows for access to svn functionality from within your ant scripts.  Several of the svn operations are available, and are documented here.  Personally, I think that your build system shouldn’t be mucking around with your source control system, though it is useful to use the subversion revision number as part of your build numbering system.

<target name="find_revision" description="Sets property 'svn.info.lastRev' to head svn revision">
<path id="svnant.libs.path>
		<fileset dir="libs">
			<include name="svnant.jar"/>
			<include name="svnClientAdapter.jar"/>
		</fileset>
	</path>

	<!-- Load SvnAnt -->
	<typedef resource="org/tigris/subversion/svnant/svnantlib.xml" classpathref="svnant.libs.path" />    

	<!-- find head revision number, amongst other things. -->
	<!-- Replace svn_username and svn_password with values appropriate to your system -->
	<svn username="svn_username" password="svn_password" javahl="false">
		<info target="." />
	</svn>

	<!-- Display svn revision number -->
	<echo>Revision found: ${svn.info.lastRev}</echo>
</target>
Advertisements

Tags: , , ,

2 responses to “Getting Subversion Revision in Ant – Part II”

  1. Thabet says :

    Hey Chris,

    I was looking for a way to get revision number using Ant, until I found your previous post. It did not work with me at all since there is no hint where to find svn.exe. Later on I read your comments which lead me to this post. Unfortunately it did not work with as well.

    First I got (fileset doesn’t support the nested (incluse) element) from the path element. I changed it to (include).

    2.nd It complained about (libs not found.) Of course I added a the libs folder to the current directory where ant build is running.

    3.rd I got (Failed to set ‘info’ properties) with no clue way?

    Please, can you help out to let this script working.

    One last thing, if this script is supposed to read revision number from SVN server, where is the URL to the repository such as https://svnant4java.googlecode.com/svn/trunk/ ?

    Info:
    – OS in Windows XP
    – I tried to run this script within Eclipse and from DOS.
    – Ant version 1.7.1

    best regards

  2. ccollins says :

    @Thabet,
    Thanks for pointing out the typo. It has now been fixed. Sorry for the confusion, “incluse” should have read “include”.

    I’m not 100% on this, but I think the path has to be a path, as the typedef requires a path reference. I’m not sure that a fileset world work. Check the Ant documentation for definitive information.

    Once you have the libs directory set up, you’ll need to put the SvnAnt jars in it. Download them from the SvnAnt site linked. This should also fix your third issue.

    Finally, this is expected to run within the file system of a checked out project. The SVN tool itself knows the URL the code was checked out from.

    -Chris

%d bloggers like this: