Decision to use Ivy is a no-brainer
Now that Ivy 1.0 is out, I’d strongly encourage every Java developer to pull it down and consider using it to manage dependencies in their Ant builds. As far as I’m concerned, it’s a complete no-brainer.
Ivy does one thing, manage dependencies, and does it quite well. What’s nice is that it has a decent set of defaults, so starting to use it is trivial, but the model is also powerful enough to handle declaring and managing dependencies for complicated multi-project builds.
If you have typical simple Ant build with one project with a lib dir with a bunch of Jar files in it, then getting rid of those baked-in jars (from CVS) and having Ivy instead pull down (with caching) the jars you need (along with all their transitive dependencies) can be as easy as adding the following to your build file:
and creating an ivy.xml file describing your project dependencies:
While everything is pluggable, in a default setup like this, Ivy will pull down your dependencies (i.e. Jar files), as declared, from the well-known iBiblio repository. It will also look on a parallel ‘IvyRep’ repository for optional ivy.xml files describing the dependencies of those dependencies, so that in fact what you retrieve is a transitive closure of all your dependencies and their dependencies, and so on.
The important thing though is that while simple cases are easy to handle, and there’s immediate value, the Ivy dependency model is powerful enough to handle pretty well any complex multi-project dependency setup. Considering all the hand-written, adhoc dependency management XML code I’ve had to do in Ant builds for multi-projects applications over the last 5 years, I would have killed for something like Ivy. (Never mind all that wasted space in CVS duplicating dependencies; iBiblio aside, there’s often a value to having dependencies in CVS somewhere, but ideally this is in a shared location accessible by something like Ivy, not duplicated in every project as is typically done).
Here’s a nice XSLT generated HTML view of an XML Ivy dependency declaration file which shows to what level you can take things. Basically, any module can declare a set of configurations which specify what external libs are needed (along with their transitive dependencies) for those configurations, and then the module can declare what artifacts it publishes itself, and what configurations are needed for those. Artifacts can be retrieved from multiple, pluggable, repositories and module artifacts when generated can be published back to those repositories to handle integration builds for example. It’s also possible to generate a nice report of the actual dependencies resolved for a module (also check out this variant shown graphically), or a nice view of all the libraries available in a repository
Give it a try, I don’t think you’ll go back to manual dependency handling! Ivy is BSD-licensed, by the way, meaning it should be usable anywhere.


Modified

Jason Carreira says:
Added on April 29th, 2005 at 4:06 pmSo I guess you’ve made up your mind now
Nice write up.
Marc Logemann says:
Added on April 29th, 2005 at 6:37 pmI am following the progress of ivy for a few months now and i am quite thrilled but somehow i feel that i am losing something when putting my libs out of Subversion/CVS. Often i am working from different sites with different PCs. Right now its easy to just checkout my project and i get all the stuff i need. When using ivy, i assume i have to create my own public ivy repository, because i am not only using standard jars which can be possibly found in iBiblio but also more or less custom ones.
Perhaps i should check their maillist to find the answers that blow away my fears.
Colin Sampaleanu (blog author) says:
Added on April 29th, 2005 at 7:27 pmThere are a couple of ways to handle what you describe. First of all, the normal pattern with ivy is to retrieve the dependencies to the lib dir, either right directly inside lib, or else to different subdirectories under lib which are named after the various configs (think compile-time vs test-time vs runtime, etc.). Then you just build classpaths in standard fashion for ant. So there’s nothing stopping you from also just having a
lib/static
dir which holds the jars which you are not going to retrieve though Ivy, and this directory gets checked in.
Now this is probably not the preferred form. As you say, it’d be better to have another repository somewhere with your non-standard jars, and have Ivy retrieve those from there. But this is not a big deal. A filesystem reposiroty is just a directory with the jars in a standard hierarchical format (the format is definable by you) underneath it. So if you want, if nothing else is going to be using those jars, you can have a ‘repository’ dir right inside your project. Then Ivy will get some jars from iBiblio, and some from that internal repository. What’s nice about this is that all dependencies, no matter where they come from, are listed in your ivy.xml file, and you get them shown in the reports, etc.
There is also nothing stopping you from structuring your build so that normally ivy doesn’t run at all, i.e. it’s a manual process to run ivy and pull stuff down into your lib dir. Then you check those in, and build normally as if the project wasn’t even using ivy. Now I wouldn’t really work like this myself, but it’s certainly viable.
Marc Logemann says:
Added on May 2nd, 2005 at 6:51 amYeah i followed some discussions in the ivy forum and you are correct with your solutions. I have some multi module projects with some dependecies of module A from module B, it seems that i can handle this too, because i saw that you have the same needs with Spring (Spring X module is depending on Spring-core etc.) So after all i will use it, but as it seems, it definitely takes some time to get into it when having more than just a flat project structure. I will follow your progress with the Spring project and ivy during the next weeks
Graham Lea says:
Added on May 4th, 2005 at 9:22 pmSo, Ivy handles dependencies…
Let’s say I require commons-digester 1.4 (I’m making this up, BTW).
So I create a dependcy list containing just that.
Now, let’s say commons-digester 1.4 requires commons-logging 2.1.
I assume the purpose of Ivy is that it will also get commons-logging 2.1 for me, without me having to know that commons-digester needs it?
But what if I want different dependencies to what something describes for itself?
For example, what if I want commons-digester 1.4 to run against commons-logging 2.3?
Is it possible to do this kind of overriding with Ivy?
Thanks.
Matthieu Brouillard says:
Added on May 9th, 2005 at 7:16 amHi Graham,
yes you can do what your are describing with Ivy and you can more.
Ivy is very simple to use and also very powerfull and configurable to handle all the different configurations you can imagine.
Just take a look at the Ivy site : ivy.jayasoft.org, i think you will find some answers to your questions.
Do not hesitate to jump into Ivy world
lf says:
Added on May 12th, 2005 at 2:56 amdear sir:
I am very sorry to bother you , I am a student and now I want to write a paper about spring or J2EE but I only know little about them ,I first plan to write a paper about distributed transaction in spring ,but I found spring do well throught the integration of JTA ,so I was lost and does’t know which aspect I should write ,can you give me some constructive advice ? or give me some I interesting tile about spring that worth studying ,I know in spring you are very famous .your swift reply will be very much appreciated.Thank you very much !
Best regards.
lf
minvfeng@163.com