Java Reference
In-Depth Information
9.6
Dependency management with Ivy
When your project is small, it can be easy to deal with the JAR files your code depends
on. In our previous example, we depended on only one JAR file, junit.jar. For larger
projects, your build may end up depending on dozens of libraries. These dependen-
cies can trip up new developers or downstream developers of the project. Having to
know what the JAR dependencies are and where to get them on the web should not be
an impediment to developers using your project.
The Apache Maven project first introduced dependency management for Java
projects (see the next chapter for coverage of the Maven build tool.) Maven depen-
dency management is based on the concept of one or more (internet, network, or
local) repositories containing JAR s from many projects from all over the open
source world. The developer lists dependencies for a project in a configuration file
and lets Maven download the right files to a local repository cache on your
machine. You can then add the JAR s to your classpath based on their location in
the local repository.
Apache Ivy 6 is a popular open source dependency management tool (used for
recording, tracking, resolving, and reporting dependencies), focusing on flexibility
and simplicity. Although available as a standalone tool, Ivy works particularly well with
Ant, providing a number of powerful Ant tasks ranging from dependency resolution
to reporting and publication. It's out of the scope of this topic to cover Ivy in depth,
but we rework our build file with dependency management using Ivy.
The installation of Ivy is straightforward; download the zip file from the website,
extract it, and copy the ivy-vvv.jar ( where vvv stands for the Ivy version) to the
${ ANT_HOME }/lib directory.
Ivy works in the same manner as Maven and even uses Maven repositories for
resolving and downloading dependencies. You specify the dependencies for your proj-
ect in a file named, by default, ivy.xml. Ivy will download all the dependencies listed in
the ivy.xml file into a local cache directory.
Listing 9.4 shows the build file with changes highlighted in bold.
Listing 9.4
Adding the Ivy changes to the build file
<project name="example" default="test"
xmlns:ivy=”antlib:org.apache.ivy.ant” >
<property file="build.properties"/>
B
[...]
<ivy:retrieve file="./ivy.xml" sync="true"/>
C
D
<property name="junit.jar" location="lib/junit-4.6.jar"/>
[...]
<target name="compile.test" depends="compile.java">
<mkdir dir="${target.classes.test.dir}"/>
<javac destdir="${target.classes.test.dir}">
6
http://ant.apache.org/ivy/
 
 
 
 
 
 
 
 
Search WWH ::




Custom Search