Saturday, May 19, 2007

IVY dependency manager (Part1 Introduction) Contd....

Himath requested to discuss the dependency management in detail. Thanks himath for your feed back. I will try to explain this in more detail on this post. Today will discuss on dependency management in detail before go in to the IVY guide lines.

Dependency management is , like its name suggests ,
Managing the project dependencies in a centralized storage.
For example, if we are using spring-1.2.8 in our projects A and B. Then assume spring 1.2.8 has dependencies of commons-logging-1.0.4 and log4j.1.12 dependencies. So what we have to do is , we should have a lib folder inside our projects and have these all dependencies into it. So what are the headaches for doing this.

  1. You have to keep remember of these dependencies each every time you add a new lib. For example if you are going to have new dependency like foo.jar , the you should know which are the dependencies of foo.jar.
  2. You have to keep jar files in your project repositories. For example, we may need to keep spring jars for all the project repositories which uses spring.
  3. Switching from one version to another is very difficult. For example I am moving from spring 1.2.8 to spring 2.0 version. Then again I have to add the new dependencies to my project dependency folder.
  4. Maintaining project artifacts is difficult. For example we have sub modules a, b and c in our project and we need to b and c jars for building a, we may need to build the b and c first before build the a.jar, even though we haven't changed the code base of b and c.

Above are few of the many problems we face when we don't have a centralized dependency management system.

So now lets discuss the advantages of having a centralized dependency management system.
If we have a dependency management system , then all of our artifacts (For us, it is mostly jar files) are in the central repository (Another svn repository). Every artifact has a configuration file where you have your dependency information. This is an extract of a configuration file for a sample. (This is taken from one of our projects etl-server)


Here you can see etl-server-core-1.1.jar is the artifact and dependencies for this artifact are listed inside the dependencies tag. So that tells the story. You have spring 1.2.8 is in the dependency list. So you don't need to separately keep the log4j dependencies here since you have those entries already inside the spring dependency file. If you look this in to more, which ever the projects using the etl-server-core-1.1.jar, they don't have to keep the these dependencies inside their list. Because these dependencies are already referred through etl-core-server jar.

So lets list down the point now.

1) Using dependency management we can maintain the centralized repository. So in your project page, you only need to use a XML file listing your dependencies. Ivy will take care of downloading them from the dependency repository when we build the project using ant.

2) Ivy maintains a local cache directory (possibly inside your /.ivy folder) for your downloaded dependencies, so you don't need to download them each and every time. This download is one off.

3) To publish your project artifact to repository is as easy as using an ant command publish!

4) Due to the chain of dependencies concept, if you refer one artifact foo.jar in your dependency file, then whatever the dependencies needed for foo.jar will be taken care of foo's dependency file. You don't need to keep them inside your dependency file.So it makes your life much easier.

So for more details it is better to have a go through the IVY DOC site before we discuss this matter in to more detail.

No comments: