Tuesday, January 19, 2010

Ant version 1.8 is nearing release

The Apache Ant developers have made a release candidate build of Ant 1.8 available for download.

As I looked at the recent work on Ant, I realized that I've now been using Ant as my primary build tool for almost a decade now. I experimented with Ant 1.1 and wrote some of my first Ant build scripts using Ant 1.2, some time in the fall of 2000 or possibly the winter of 2001.

Periodically I've looked at some other build tools, but I keep sticking with Ant. Partly this is because I have a large body of existing Ant scripts, but partly it's because the other build tools that I've seen haven't offered any huge breakthroughs. The most promising contender that I saw was Rake. Is Rake being actively developed and enhanced? I haven't looked at Rake in several years.

The most interesting Ant release was version 1.6; Ant completely changed as of release 1.6 and went from being a frustrating tool to being a powerful and usable tool, all because of two features:

  • macrodef

  • import

Before these features were added, it was very hard to modularize your Ant scripts and build them as independent re-usable build files, but with careful use of macrodef and import, it is certainly possible to build enormous systems while still retaining a reasonable amount of legibility and maintainability.

In my experience, there are three types of Ant scripts that you encounter "in the wild":

  • Small Ant scripts, generally Java-only, which can use most of Ant's default behaviors and are clear and simple. A lot of open source build scripts are this way.

  • Serious commercial Ant scripts written before macrodef and import became available. These are generally impossible to understand and evolve, and the reality is that a small cadre of Build Wizards keep them running. Such systems often involve a substantial number of custom Ant tasks.

  • Serious commercial Ant scripts written to use macrodef and import. In my experience, the need for custom Ant tasks drops way off with Ant releases post-1.6.

With a certain amount of effort, build scripts in the second category can be transformed into build scripts in the third category. Here's a nice article that explains a reasonable approach. I went through a similar effort at my day job in 2005-2006, and the result was well worth it.

I was recently looking at the Android developer kit's use of Ant scripts and it was rather surprising, as your project's script is quite small and clear. An extremely clever custom Ant task provided by the Android developer kit runs at startup, and automatically generates your build on-the-fly by importing the android_rules definitions into your project.

I'd like to learn more about how the Android developer kit's custom Ant tasks work; is the source code for the Android developer kit itself available as open source? I should go look and see if I can figure out how that magic actually works.

No comments:

Post a Comment