ant Getting started with ant Bootstrap Apache Ivy


Add the following target in your build.xml

<!-- Bootstrap ivy -->
<target name="ivy.bootstrap" description="Download Apache Ivy">

    <!-- Define the version to use -->
    <property name="ivy.version">2.4.0</property>

    <!-- Create directory if not exists -->
    <mkdir dir="${user.home}/.ant/lib" quiet="true" />

    <!-- Download it -->
    <echo message="Downloading Apache Ivy..." />
    <get dest="${user.home}/.ant/lib/ivy.jar" src="${ivy.version}/ivy-${ivy.version}.jar" />

After running the task ant ivy.bootstrap, you will now be able to resolve dependencies using apache ivy.

<target name="ivy.resolve" description="Resolve all artifacts.">

    <!-- Define lib driectory -->
    <property name="dir.lib">lib</property>

    <!-- Create directory if not exists -->
    <mkdir dir="${dir.lib}" />

    <!-- Configure -->
    <property name="ivy.dep.file" value="ivy.xml" />
    <ivy:settings file="ivysettings.xml" />

    <!-- Retrieve to a defined pattern -->
    <echo message="Resolving dependencies..." />
    <ivy:retrieve pattern="${dir.lib}/[artifact](-[classifier]).[ext]" />

Define your resources in ivy.xml

<ivy-module version="2.0">
        <info organisation="org.apache" module="java-build-tools"/>
                <dependency org="junit" name="junit" rev="4.11" />
                <dependency org="org.apache.commons" name="commons-compress" rev="1.9" />

And any custom repositories in ivysettings.xml

    <settings defaultResolver="chain"/>
        <chain name="chain">
            <ibiblio name="central" m2compatible="true"/>
            <ibiblio name="github" m2compatible="true" root=""/>

Download your dependencies by running ant ivy.resolve.