Coordinating Ant targets for faster builds
Do you have a long running build? Often times, the testing aspect of a build (i.e. executing a suite of JUnit tests) consumes the vast majority of time; however, code inspections have also been known to add quite a bit of time, especially when the code base is large. If you find that your inspections are long running, there’s a quick and easy way to speed things up: use Ant’s parallel task.
For example, imagine the following target takes enough time that warrants you either stop running it or figure out a way to make it execute faster:
<target name="inspect">
<antcall target="pmd"/>
<antcall target="javancss"/>
<antcall target="simian"/>
<antcall target="jdepend"/>
<antcall target="findbugs"/>
</target>
As you can see, this target simply calls a series of inspection targets sequentially. With Ant’s parallel task, you can effectively force Ant to launch these targets in multiple threads. Just be sure that these targets don’t interact with each other– just like coding in threading, you’ll have to think through scenarios where using parallel is helpful and where it’s not.
I can take the target defined above and wrap the antcall invocations with parallel and boost performance. Of course, results will vary; however, for a particular project on which I applied this technique, I saw a measurable improvement in overall build time execution.
<target name="inspect">
<parallel>
<antcall target="pmd"/>
<antcall target="javancss"/>
<antcall target="simian"/>
<antcall target="jdepend"/>
<antcall target="findbugs"/>
</parallel>
</target>
There are many culprits that contribute to prolonged builds; nevertheless, there are a number of techniques that can assuage long running targets, including running them in parallel. That certainly beats the “just don’t run them” alternative too!

March 13th, 2007 at 4:37 pm
Wow! really nice, I wish the Maven team does something likes this to speed up reporting when creating a site. Thanks for the tip Andy.
March 14th, 2007 at 9:10 am
Hi,
This is really a good one. Now I can run my ant targets in paraller and acheive the speed in my build.
Thanks for this tip Andy.