Why I Hate Ant

February 15, 2010

OK, let me address the title of this blog before the whole Java open source community jumps down my throat.  I do not really hate Ant, in fact Ant is a great and invaluable tool.  Ant helps simplify building and deploying Java applications.  It is extremely powerful and flexible and allows you to do pretty much anything you want as part of your build process.  Ant's flexibility is what has helped it gain popularity in the Java community, and this flexibility is at the core of my Ant critique.

I came to this realization recently when I recommended to a colleague that I help him convert his open source project from Ant to Maven.  I have spent the last three years evangelizing the tenants of Maven over Ant and how it solves many of Ant's problems (conventions over convenience, dependency management).  I also enumerated some of the issues I have experienced with using Maven, such as dependency bloat, steeper learning curve, and decreased build transparency to name a few.  In spite of this, I still felt that Maven was a better solution for most open source projects and can help projects integrate quicker.

Once it was agreed that Maven was to be used as the build management tool, I set off looking at the Ant build script for the project.  I began this endeavor confident that I could quickly dissect the build script and convert the project to Maven.  This confidence, however, was misplaced as I forgot how complex Ant build scripts can get.  I spent the next hour or so building a reverse call tree from the Ant target hierarchy.  Once I had this call tree, my next step was to figure out what each of these targets did so I could map them to a Maven lifecycle phase and an appropriate plugin.

The biggest problem with Ant is the complexity of the builds scripts.  A new developer has no way of knowing what the build steps are until he literally walks through the call stack of the Ant targets.  This can take a while and can be complex, especially if the Ant script was written by a pro.  Now this process may sound similar to following the call stack of any application you are new to, and it is.  But Java applications have Javadocs (or they should) to provide a simple way of understanding the code and most applications utilize design patterns as a common language for how the code is organized.  Ant doesn't have a documentation standard and it doesn't utilize design patterns for organizing targets.  An Ant script is essentially a functional program for your build process.

There are other reasons why I prefer Maven over Ant, some of which I mention above, but in the end, this reason far outweighs all the others.  Maven's convention over configuration approach makes understanding build scripts exponentially easier than it does in the Ant world.

Share this:


comments powered by Disqus