tags:

views:

1181

answers:

7

It seems that ant dependency management isn't great to say the least... But, is there hope? Today there are better choices for build or project management such as maven, ivy but I'm stuck with a bunch of ant project that depend on one another so I was wondering if there's an "ant best practice" for managing dependencies.

Specifically in my case I have:

w.war

a.jar
b.jar
c.jar

w.war is the war file I deploy to the web server. In the war file I use a.jar. a.jar depends on b.jar, so I happily package b.jar into w as well... That's sort of OK until... The problem starts when b.jar depends on c.jar. The author of a.jar knows about its dependency on b.jar so it can package b.jar into w.war, but it is not aware of the dependency of b.jar on c.jar. Moreover, the author of b.jar could later add even more dependencies such as "b.jar depends on e.jar", so the author of a.jar has no chance following these dependencies as they add up.

What I'd like to have is define "a depends on b" and "b depends on c" (in a different build.xml file) and use ant magic to compile them all into w.war. Is that possible? If not, is there a Best-Practice?

I'm this-close to just rewriting is all in maven, but it's a lot of work... Is there hope to ant?

+6  A: 

If you already use Ant, then your best bet is to use Ivy for dependency management.

http://ant.apache.org/ivy/

It provides a rich set of ant tasks for dependency manipulation.

skaffman
+1  A: 

maybe Ivy?

dfa
+2  A: 

Just to disillusion you: dependency management in combination with a build system is hard! Unless you have a really simple example this is not a no-brainer, and you will have to invest some work.

If you want to or have to use Ant, Ivy is definitely a good choice. Being an soffical subproject of Ant it integrates relatively smoothely.

jens
I'm way beyond illusions, but thanks ;-)
Ran
+1  A: 

I've been using Ivy for the last 4 years (way before it joined Apache) and haven't had any regret.

Without knowing much about your Ant files, it's a little bit difficult to give a definitive answer but I guess that the projects are build in one go. This means that they can't individually publish their artifacts (or jar files) into a central repository.

The solution is to use both a central (for common libraries) and local (for your project) repositories. You can take a look at my public projects and especially the ivysettings.xml file because they use exactly this very principle.

Vladimir
A: 

I came across this solution for project dependency in my search. What do people think about this? Is this standard practice?

http://www.exubero.com/ant/dependencies.html

Tazzy531
A: 

I just added "best/standard practice" to my "Bullshit Bingo" layout.

xcramps
A: 

Here's my take: use the best of both worlds: Maven just for dependencies and Ant for your day-to-day build heavy-lifting:

Why you should use the Maven Ant Tasks instead of Maven or Ivy

Peter Thomas