Skip to content

Dependency management (Java, Apache Ivy)

by drphrozen on July 19th, 2012

Today i had some spare time and decided to play a little with dependency management. I am a BIG fan of NuGet (package manager for Visual Studio) but since im also a big fan of Eclipse, i decided to see what options i had in the Java world.

I did some research into dependency/package managers for java, and found Apache Maven and Apache Ivy as possible candidates. At first i tried Maven, since this seems to be the industries most popular choice. I had some experience using Maven to build libraries i needed (like protobuf) and it was easy to use from the command line. Next i tested the integration with Eclipse (m2e). Integration seems to be working fairly well, but it isn’t to user friendly (especially not compared to NuGet).

Next up was Apache Ivy™… Trademarked, didn’t notice that before :-) … Well, Apache Ivy works as a task for Apache Ant™ and i know that Eclipse has a builder for Ant build files and is somewhat easy to setup. At first Ivy was looking a lot like Maven, but instead of a dedicated “mvn” command i had to create a task in an ant build.xml. Then just run “ant” and watch Ivy download dependencies and their javadoc/sources. The tutorial at Apache Ivy’s homepage are of high quality, but just to show how simple it is to configure Ivy, look at this (ivy.xml):

<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0" 
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
  <info organisation="org.apache" module="hello-ivy"/>
  <dependencies>
    <dependency org="commons-lang" name="commons-lang" rev="2.0"/>
    <dependency org="commons-cli" name="commons-cli" rev="1.0"/>
  </dependencies>
</ivy-module>

So simple. And then just add this (build.xml):

<project xmlns:ivy="antlib:org.apache.ivy.ant" ... >
...
  <import file="ivyinit.xml" />
  <target name="retrieve-libs">
    <ivy:retrieve />
  </target>
...
</project>

This will retrieve the dependencies using the ivy.xml. Easy!

The import task is not actually necessary, but i wanted to have an environment with a minimal set of required tools to be able to build this, and the import task actually runs an ant build file that retrieves ivy.jar from apache.org and registers Ivy for use in the rest of the build file. That’s awesome!

The next step was to see hoe well Ivy integrates in Eclipse using Apache IvyDE™. A need thing about the plugin is that now we can add a reference to an Ivy Library and this one is automatically populated using ivy.xml. This is very handy since Eclipse’s Ant integration seems to only add classpath entries on import the Ant build file.

I am definitely going to recommend Ivy over Maven, mostly because of the simplicity, but also because Ivy is able to use both Maven repositories but also a lot of other resolvers (like ftp, http or custom ones). Although it is very easy to setup Ivy and to maintain the dependencies, it is not as easy as NuGet. So maybe my next project should be to develop an Ivy plugin to automatically search for and configure dependencies. :-)

From → Uncategorized

2 Comments
  1. Ronni permalink

    Very interesting article. I found Ivy to be a pretty awesome tool to find those missing dependencies. Thanks for the tip (as usual) :-)

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS