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="https://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.version}/ivy-${ivy.version}.jar" />
</target>
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]" />
</target>
Define your resources in ivy.xml
<ivy-module version="2.0">
<info organisation="org.apache" module="java-build-tools"/>
<dependencies>
<dependency org="junit" name="junit" rev="4.11" />
<dependency org="org.apache.commons" name="commons-compress" rev="1.9" />
</dependencies>
</ivy-module>
And any custom repositories in ivysettings.xml
<ivysettings>
<settings defaultResolver="chain"/>
<resolvers>
<chain name="chain">
<ibiblio name="central" m2compatible="true"/>
<ibiblio name="github" m2compatible="true" root="http://github.com/"/>
</chain>
</resolvers>
</ivysettings>
Download your dependencies by running ant ivy.resolve
.