Ant Contrib: the power and the pain

I got a comment from Errno on my last post:

“Everyone agrees that Ant Contrib means you’ve done something wrong.” why? is there any blog post/write-up describing this? thanks

I don’t know of any write-up. So I’ll make one. There’s a reason why some tasks are in ant-contrib and not the Ant tool proper: they don’t really fit the tool. The culprits that I have in mind are trycatch, for, and variable.

Now don’t get me wrong: these keywords would all be great in dozens of languages. Catching exceptions: Great! Iterating! Sweet! With a local variable! Sweeter!

But not in a declarative language. Because that’s what Ant is. It’s a declarative DSL for building Java code. Declarative programming allows you to present the facts to the language, and let it go do all the plumbing. So flow control in your Ant scripts aren’t needed, if you go about it the right way.

What’s more, properties are immutable. You need never test to see if a property is set before setting it. They did that for a reason: it’s subtly very powerful.

Perhaps it’s too subtle. Ant’s a powerful tool if you go with the grain. There’s a couple of other things to consider if you find yourself using the Ant-contrib stick:

  • Should you be using Ant at all? Remember, it’s a build tool. If you’re bending the tool to fit your needs, perhaps another will be better.
  • If you do need to get a bit more imperative, perhaps you could write an Ant task and share it with the world? Then we all get to enjoy a simple build.

Yes, I’m a build tool socialist. Want examples? Send me a snippet of build and I’ll tell you how I’d do it The Ant Way.

Image via merfam

%d bloggers like this: