Are you using <ivy:cleancache>
? This is why your rebuilds are so short, but your initial builds are so long.
Ivy is going to be slower than using Ant without Ivy. Ivy has to download each and every jar you specify, plus all dependencies into the Ivy cache (which by default is $HOME/.ivy2/cache
on Unix/Mac/Linux and %USERPROFILE%\.ivy2\cache
on Windows) before it can begin. You might specify 4 or 5 jars, but these could depend upon others which might depend upon even more.
There really isn't a way to speed up the Ivy downloading of jars1, but once jars are downloaded, there really isn't a reason to constantly clean the Ivy cache each and every time you do a new project, or when you do a clean.
What you can do is setup your clean, so you can avoid cleaning the Ivy cache unless you specify it:
<taskdef uri="http://ant.apache.org/ivy"
resource="org/apache/ivy/ant/antlib.xml">
<classpath>
<fileset dir="${ivy.dir}">
<include name="ivy*.jar"/>
</fileset>
</classpath>
</taskdef>
<property name="ivy.cleancache" value="false"/>
<target name="clean">
<if>
<istrue value="${ivy.cleancache}"/>
<then>
<ivy:cleancache/>
</then>
<if>
<delete dir="${target.dir}"/>
</target>
This way, running ant clean
won't scrub your Ivy cache every time, and you can reuse it over and over again. If you want to clean the Ivy cache you need to do this:
ant -Divy.cleancache=true clean
Yes, this is using antcontrib
. I use my special Ivy directory configuration to configure Ivy for everyone and while I'm at it, to include definitions for ant-contrib, plus Findbugs, PMD, and other useful tools.
However, it might be possible in Ant 1.9 not to have to do this:
<property name="ivy.cleancache" value="false"/>
<target name="clean">
<ivy:cleancache if:true="ivy.cleancache/>
<delete dir="${target.dir}"/>
</target>
I haven't tried this, but if it works, you don't have to use antcontrib. Of course, you could do this too:
<target name="ivy.cleancache"
if="ivy.cleancache">
<ivy:cleancache/>
</target>
<target name="clean"
depends="ivy.cleancache">
<delete dir="${target.dir}"
</target>
Then you could specify:
$ ant -Divy.cleancache clean
to clean your Ivy cache and simply put ant clean
to clean your build without cleaning the Ivy cache.
1. You might be able to speed up the downloading of jars if you use your own Maven repository like Nexus or Artifactory. These will have their own cache which will store the downloaded third party jars locally. This is a bit faster than going outside your network to find these third party jars, but they all still have to be downloaded. Maybe instead of taking 26 seconds, it might only take 20 seconds.
ivy:resolve
every build, just when the dependencies change? I separateresolve
out to ainstall
build target that is run by hand rarely.cachepath
is still 4s though – Chinchilla