Archive for April 13th, 2006

Ant Strategy 01: Treating build scripts as first class citizens

Thursday, April 13th, 2006

Every Java project that I have worked on over the past five or so years has been dependant upon Ant for generating distribution packages. The time spent on these projects has ranged from only a few days through to many months and in some cases more than a year. As the code base continued to grow on each of these projects, so did the reliance upon Ant to compile, test and package the project artefacts. As a result, the project build scripts become some of the most valuable lines of code in any given project. For this reason it is important to consider the Ant build.xml file as a first class citizen on all projects.

For Ant build scripts to be promoted to the level of first class citizen, it is necessary to elevate these scripts to the same level as the application code itself. What this means is that Ant build scripts are subject to the same principles as applied to application code. That is, Ant build scripts need be in a working state throughout the project lifecycle. As with application code, the build scripts should evolve through the use of testing and refactoring. It is important that the process of refactoring be applied to build scripts to help improve the quality of the build as the project team evolves.

Refactoring is performed to ensure that:

  • the build script clearly documents the build process without relying on external documentation or comments
  • there is a minimal amount of duplication in the build script
  • the build script performs in the way that it is intended
  • changes can be performed efficiently and without introducing new bugs

Build scripts also benefit from the use of consistent coding standards, subsequent strategies shall provide suggestions on how to structure a build script based upon my experience as an Ant user for more than five years.

Ant Strategies

Thursday, April 13th, 2006

For a while now, I have been playing with the notion of posting an article on the strategies that I use to develop and maintain Ant build scripts. The hump that I have had to get over however was the fact that I needed to sit down, structure my thoughts and write two or more thousand words on this subject. Due to other interests and obligations this is never likely to happen. Instead I have opted for writing this article incrementally with a blog entry for each strategy.

Before getting started, if you are interested in learning more about Ant prior to being influenced by my suggestions, check out the Apache Ant project home page. You may also find a recent article by Russ Olsen in addition to the Top 15 Ant Best Practices article over at OnJava to be good starting points.