It's a good idea to try to standardize on the targets across build files. Adopting a target-naming convention ensures all build files between projects are consistent and more easily understood and maintained by members of the project team. Table 12-1 offers some naming suggestions for the common Ant build targets.
Table 12-1. Naming Suggestions for Ant Build Targets
General utility target for performing any setup tasks, for example, creating directories, copying files, or performing dependency checks. This target is seldom invoked directly from the command prompt but is instead called by other Ant targets.
The clean target removes all generated build artifacts, thereby ensuring any subsequent builds regenerate all targets.
This target compiles all source files. It may also be dependent on a generate target, which invokes any code generators that are part of the build process.
The package target takes the output from the compile phase and packages up all files ready for deployment. This target is sometimes named dist.
Use the make target for initiating incremental builds. This target requires conditional dependencies to be correctly set up between the different build targets.
Performs a clean followed by a make, thereby ensuring the entire application is built from scratch.
Deploys the built application to the designated application server. An undeploy task is also useful for removing the application from the server.
Use this target for running all unit tests. The test target should be run regularly and preferably included as part of an overnight build process.
Generates all the Javadoc documentation for the project.
Retrieves the latest version of the project from source control. You might want to consider defining an overarching target that fetches the latest code, performs a complete build, and then runs all unit tests.
These suggestions are for a minimal set of build targets; your project will probably have many more. For example, you could add a run target to launch any client applications as well as start and stop targets for controlling the application server.
Applying a consistent naming convention becomes more important with Ant 1.6, as the use of <import> makes it possible to override the targets of other build files within an inheriting Ant build file.
Ensure you provide a good level of help for all targets within the build file. Use the description attribute of the target element for this purpose. You can then launch Ant with the projecthelp option to see a list of all targets, complete with descriptions, that are supported by the build file.
You must specify dependencies between each target. Figure 12-2 shows the output from Antgraph based on the targets defined in Table 12-1.
Figure 12-2. Target hierarchy as generated by Antgraph.
For larger projects comprising multiple modules, we need to consider how the overall project is organized. The next section provides guidelines for addressing this issue.