Ant Strategy 01: Treating build scripts as first class citizens
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.