Enhancing Your Build Scripts

Having established your CruiseControl service, the next step is to go back to your build script. There are a number of features that are useful in a script (which is automatically built) that you probably wouldn't bother putting into a script that is run only by humans.

Cleanliness Is Next To...

Automated scripts must start from a clean base. You must include a target that cleans out the project work area, removing all generated artifacts. Naturally, this should be the first target invoked by the build target. An exception occurs when you use CruiseControl to do partial builds and only do full builds periodically. In this case, the partial builds need only remove the artifacts that will later be regenerated.

Document Thyself

A common use of an automated build is to generate (and publish) documentation, particularly JavaDoc. This is an excellent task to do in a nightly build, for example.

Testing Times

While every good build script should include unit tests (and developers should run those tests themselves!), automating other tests, such as integration, performance, and acceptance tests, can pay off in an automated environment. Although developers won't normally run them since they can often be quite time consuming, it doesn't matter that much if your nightly build takes an hour longer than your daytime builds. Performance tests, in particular, are often run overnight, with endurance tests performed over weekends.

Latest and Greatest

You could create a nightly task to migrate the latest working release up to a user acceptance or testing region. This would allow testers to start each day with a fresh version.

Who Goes There?

With automated builds, particularly automated builds that deploy to servers by themselves, it is a good idea to embed the build label into the generated files in some manner. The Ant <propertyfile> task provides a good way to do this, as you can put the label property into a property file. All you need then is to provide a way to find out the label in your app. (Hint: About pages are a good place for this sort of data.)

Navel Gazing

It is worthwhile spending time putting analytical tools into your build scripts. Such tools can analyze your project and give back some metrics, some meaningful, others not so good. There are a number of such tools, and some good open-source tools are Checkstyle, PMD, JDepend, JavaNCSS, and JCoverage. These reports can be used both to examine your project for problems right now and to discover trends over time.