tags:

views:

501

answers:

4

I have read lots of articles on Ant that explain all sorts of options, and I've read much of the documentation for Ant, but I don't really know the "right" way to do many things. Can anyone recommend a Good Example illustrating how to use Ant? Something that is not too complicated but also not too simple.

I found this one by Doug Sparling (specifically related to Hibernate) and it looks pretty good but was wondering if you folks could comment on it, because I don't want to adopt the style of someone who has questionable habits, but it seems good to me.

+2  A: 

I suggest you look at the ant scripts of open source implementations that use ant for their build script. Typically the ant scripts don't get tremendous love, but they are more robust than a typical in-house job because they are distributed to so many developers that are expected to just run them in a variety of environments.

I would argue that it is a best practice to not worry about your build script beyond the point where it gets the job done and is reasonably maintainable. It is, after all, not the goal of most projects to produce a good build script. Of course, as with any best practice, there are exceptions.

Off hand, the one I looked at for JSR-310 was decent.

Yishai
+1  A: 

It's kind of old but there is this: http://www.onjava.com/pub/a/onjava/2003/12/17/ant_bestpractices.html

mamboking
+3  A: 

You might want to also look at the Ant Usage Guides from the Ant Wiki.

Kathy Van Stone
ooh, it has an "elements of style" -- thanks!
Jason S
+1  A: 

I always tend to divide my targets into 2 types:

1) targets that do stuff - compile, jar, etc. These have no dependencies and each do one and only one thing.

2) targets that you might want to run - build, deploy, etc. These are where the dependencies are specified.

The reason I do this is that allows you to have runnable targets that use an arbitrary set of the doing stuff targets. For example in a web-app it's useful to be able to deploy without compiling, running tests etc every time, which this structuring of Ant scripts allows.

When I'm working with multiple modules I'll also create a master build script that contains all the common targets, which are driven by variables in module specific properties files..

Nick Holt