Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Improve performance of ivy resolve

Tags:

ant

ivy

After migrating from pure ant to ant+ivy my project build times increased from 7s to 26s while incremental rebuilds are now 7s instead of just under 1s (nearly instant).

Most of this time seems to be spent in ivy:resolve which I need to generate classpath using ivy:cachepath.

Is there some way to speed this up, especially rebuilds ?

like image 762
Marcin Wisnicki Avatar asked Jul 15 '13 14:07

Marcin Wisnicki


2 Answers

Another option is to switch off network based resolution and force ivy to use cached data.

See the following answer for more details:

  • Resolving Apache Ivy dependencies when offline/disconnected?
like image 79
Mark O'Connor Avatar answered Sep 30 '22 16:09

Mark O'Connor


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.

like image 44
David W. Avatar answered Sep 30 '22 17:09

David W.