jump to navigation

Ant, dependencies, and slow servers January 26, 2009

Posted by Phill in General J2EE.
Tags: , ,

At work I’m working on an application which uses an Apache Ant script to build it. Unfortunately we haven’t yet got around to using Apache Ivy, however all dependencies are stored in a text file and then downloaded from a central server in the build script. Not an ideal solution but it works for our needs.

The problem comes when the central server we use to store the JAR files slows down to a crawl (which has happened quite a lot recently). The past few days, the build script has taken over 4 minutes to complete – and most of that time is spent downloading JAR files (unfortunately there are two JAR files which needed to be downloaded each time – it’s too complicated to go into now…)! So I decided to make a change to the build script.

Now, it should only download when I update the text file with the list of dependencies. How is this accomplished? By using the <condition> task:

<condition property="lib.uptodate">
<uptodate srcfile="${basedir}/lib-jarlist" targetfile="${lib.dir}/lastupdated.txt" />
<uptodate srcfile="${basedir}/lib-jarlist-compile-only" targetfile="${lib.dir}/lastupdated.txt" />

What this code is doing is checking two files (lib-jarlist and lib-jarlist-compile-only). If either of these two files have a newer timestamp than the target file (lastupdated.txt), than the condition will be TRUE. Then, all I need to do is put this in the download dependencies target:

<target name="download-deps" unless="lib.uptodate">
(download dependencies....)
<touch file="${lib}/uptodate.txt">

So, the target will only run if one of the JAR list files have been updated. Note the touch command at the end – this is important: it updates the file timestamp so that next time the script will see the update dependencies and not go off to the slow server for them.

It’s not a perfect solution, but will do until we can move to Ivy!

%d bloggers like this: