Apache Ant/Best Practices/Standard Targets

Standard Targets

edit

One of the things that you learn is that if you name things consistently between projects, it is much easier to find things you are looking for. When you work with other people, you also want to have targets that you both are familiar with.

build.xml

edit
  • Place your main build in a file called build.xml in the main directory of your project.
  • Do not put references to local file systems (Windows C:\ etc.) in your build file. Isolate these all in a local.properties file in the main directory.

Folder standards

edit
  • src - the location of your source code
  • build - the output of a build process

Standard ant targets

edit

init

edit

This target should create all temporary directories within the build folder.

clean

edit

This target should remove all compiled and intermediate files leaving only source files. It should remove anything that can be derived from other files. This would be run just prior to creating a zip file of the project, and in case of gremlins occurring during the build process.

build

edit

This target should compile sources and perform transforms of raw data.

install

edit

The install target should be used to copy files to a testing or production system.

Other Standards

edit

Use the <description> element to describe what your target does.

If you have more than around 100 targets in your build file, it becomes unwieldy. You could consider calling a separate build file, but that adds other complications such as the dependency between targets.