ant + svn = love

Back in December, I built a system where my SVN post-commit hook automatically updated a file containing revision info for an application I’m writing.

Well, a few things got shuffled in our ant buildfile and that script stopped working. Not because it was bad… just because files moved around and nobody thought to update it.

My group is currently moving away from allowing Flex Builder to handle our compilation and to just using ant on both dev workstations and for server-side deploys. This got me fiddling with ant a bit more this morning and resulted in my stumbling across the SvnAnt ant task. A bit more fiddling, and I now have ant generating the version.xml files for us at build/deploy time in stead of relying on the shell script.

SvnAnt is cool. It can perform most svn operations for you from within your ant builds. This means you could automatically push builds to a server or use ant to expedite the creation of new repositories, or whatever.

My adventures with SvnAnt have born two neat little toys:

  1. I now have a build target that automatically updates both the current repository AND my classpath repository (in case I forget to poke one or the other).
  2. I also have a build target that extracts revision versions and builds my xml data file for me. No more stale files on the dev side of things and the ant version is much more robust – it works even when we move files around 🙂

installing svnant

I downloaded SvnAnt and dumped the jar files into a /lib dir in my repository. This simplifies builds tremendously if the jar files are always kept close to the build.xml file.

I added a few lines near the beginning of my buildfile:

This loads the jar files and preps the <svn/> tasks for use.


This calls the svn update first and then continues on to execute the normal build (where “build_all” is a valid target, of course).

In my case, I have a classpath repository that I also want to update when performing this target. The location of my classpath is defined as as3ClassPath in my file, so I just add <update dir="{as3ClassPath}"/> to my svn tag, then it updates both repos for me if needed.


The version.xml generation code is likewise very painless to use.

Note that I use $$’s to escape the $’s in my output and that I use html entity codes for my >/< chars.

The result is that every time I run the build, we get a file called version.xml containing xml that (if indented for human readability) looks something like:

So… I like it. It makes me happy. There’s a lot more that the ant task can do. Take a look at the docs for more info.


So… it appears that sometimes the SvnAnt stuff isn’t behaving quite as well as it should. Namely, it fails to use the java svn interface that I thought was being included in the svnjavahl.jar file in the package… but apparently not.

If you have this problem, just make sure you have a modern version of the svn cli utilities installed. For those of you running windows + TortoiseSVN, this just means you’ll also need to download and install svn-1.4.3-setup.exe or whatever the current version may be at the time of reading 😉

If that doesn’t work, well, I’ve figured out how to make the thing work w/the JavaHL interface. Download (or current version, of course), and drop the dll contained in the zip file into your C:\Windows\System32 folder. Then restart your IDE, and voila.

Leave a Reply

Your email address will not be published. Required fields are marked *