2

At the moment I have this configuration:

build.xml:

<!-- Ivy settings start-->

    <condition property="ivy.home" value="${env.IVY_HOME}">
        <isset property="env.IVY_HOME" />
    </condition>


    <target name="download-ivy" unless="offline" description="Download Ivy">
        <mkdir dir="${ivy.jar.dir}"/>
            <!-- download Ivy from web site so that it can be used even without any special installation -->
        <get src="http://repo2.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar" 
            dest="${ivy.jar.file}" usetimestamp="true"/>
    </target>


    <target name="init-ivy" depends="download-ivy" description="Initialize Ivy">
        <!-- try to load ivy here from ivy home, in case the user has not already dropped
        it into ant's lib dir (note that the latter copy will always take precedence).
        We will not fail as long as local lib dir exists (it may be empty) and
        ivy is in at least one of ant's lib dir or the local lib dir. -->
        <path id="ivy.lib.path">
            <fileset dir="${ivy.jar.dir}" includes="*.jar"/>
        </path>
        <taskdef resource="org/apache/ivy/ant/antlib.xml"
        uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
    </target>

    <target name="update" depends="init-ivy" description="Download project dependencies">
        <!-- edited for brevity -->

        <ivy:retrieve pattern="war/WEB-INF/lib/[artifact]-[revision].[ext]" />
        <!-- edited for brevity -->
    </target>


    <target name="clean-all" depends="clean" description="Purge ivy cache">
        <ivy:cleancache/>
    </target>

<!-- Ivy settings end-->

build.properties:

ivy.install.version=2.2.0
ivy.home=${user.home}/.ant
ivy.jar.dir=${ivy.home}/lib
ivy.jar.file=${ivy.jar.dir}/ivy-${ivy.install.version}.jar

ivy.xml:

<ivy-module version="2.0">
    <info organisation="org.apache" module="hello-ivy"/>
    <dependencies>
        <dependency org="commons-lang" name="commons-lang" rev="2.1" conf="default->master"/>

    </dependencies>
</ivy-module>

This means that Ivy will be downloaded to my ${user.home}/.ant/lib and will be used from there.

How can I download it to my project library(for example war/WEB-INF/lib) and use it from there, so all my files are together and not scattered around my computer?

Jaanus
  • 16,161
  • 49
  • 147
  • 202
  • Why do want to include ivy in your delivery directory? It's only needed by ant. – Mark O'Connor Sep 02 '11 at 18:42
  • Well lets say some people run my spring application, then the file ivy.jar will be automatically placed to their `${user.home}/.ant/lib` and maybe people do not want that my application creates folders and files in their filesystem without permission. Does it make sense or I should not be worried about it.. – Jaanus Sep 03 '11 at 11:10
  • Are you releasing code as a source distribution? Otherwise it doesn't make sense, because ivy is normally used as part of the construction process. – Mark O'Connor Sep 05 '11 at 14:54
  • @Mark : I haven't really though about releasing my code or anything yet. I am just learning spring and stuff, but sometimes I give my friends the project and show how far I have developed etc. Or I give war file to some employers as "test-project" etc. But I don't wanna create some random folders and files to my employers computer. Btw yeah..i am only giving the source code or WAR file as release. – Jaanus Sep 05 '11 at 15:01
  • Understood. Hope my answer below helps. – Mark O'Connor Sep 05 '11 at 15:12

1 Answers1

4

Ivy is a plug-in to ANT.

Using an alternative directory is possible, however, you'd have to run ANT as follows, in order for ANT to pick up the ivy jar from it's alternative download location.

ant -lib $APP_DIR/lib .....

See the ANT manual for details on how ANT manages plugin libraries.

Additional note:

Ivy stores a cache of downloaded files under the following directory $HOME/.ivy2/cache. Alternative locations for this directory can be specified using the caches directive in your ivy settings file.

Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
  • Does ivy always needs to create that cache there, even when I don't download my artifacts to cache? With these settings at top, all my jars will be downloaded to my library inside project. – Jaanus Sep 05 '11 at 18:43
  • 1
    The ivy cache is an efficiency feature. If you perform an "ivy:retrieve" for an artifact already in the cache, it doesn't need to be downloaded a second time. – Mark O'Connor Sep 07 '11 at 17:26
  • I am wondering, if you can help me with this? http://stackoverflow.com/questions/7313316/using-a-custom-repository-with-apache-ivy-no-resolver-found/ – Jaanus Sep 07 '11 at 20:10
  • @Jannus: Answer posted to other question, hope it helps – Mark O'Connor Sep 09 '11 at 13:59
  • Yes Mark it helped, thanks, I hope you didn't have to do too much research because of me, but knew it by yourself hehe :) – Jaanus Sep 09 '11 at 14:30