Chapter 11. Managing dependencies

 

This chapter covers:

  • 11.1 Introducing Ivy
  • 11.2 Installing Ivy
  • 11.3 Resolving, reporting, and retrieving
  • 11.4 Working across projects with Ivy
  • 11.5 Other aspects of Ivy
  • 11.6 Summary

One topic that this book has been avoiding is this: how to manage library dependencies in Ant. We’ve avoided it because it’s hard to get right. We’ve covered the basic mechanics of setting up a classpath, but not where those JAR files should come from and how to look after them. It’s time to face the challenge of managing JAR dependencies properly.

The first step is to define the problems we have. What do we need to know?

1.  How to set up the build with the JAR files that are needed to compile, test, and run the application

2.  How to pass a JAR file created in one project into other projects built on the same machine, or even to other developers in a team

3.  How to build child projects that depend on each other in the right order

4.  How to switch library versions on demand

A single product addresses these issues, but it isn’t built into Ant. It’s an extension Antlib called Ivy. Before we introduce it, we have to look at the underlying problem: managing JAR files.

How to add libraries to an Ant classpath

The simplest way to manage libraries is to have a directory containing all the JAR files. To add new JARs, just drop them in. The classpath includes every JAR file in the directory:

<path id="compile.classpath">
 <fileset dir="lib" includes="**/*.jar" />
</path>

11.1. Introducing Ivy

11.2. Installing Ivy

11.3. Resolving, reporting, and retrieving

11.4. Working across projects with Ivy

11.5. Other aspects of Ivy

11.6. Summary

sitemap