A guide to Ant, an advanced build system

From Elvanör's Technical Wiki
Revision as of 14:55, 14 March 2007 by Elvanor (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Ant is a very advanced and flexible build system. It seems really modular and able to accomplish a lot of tasks. However, it also seems complex to understand and learn.

The Basics

  • Ant build files are XML files.
  • These XML buildfiles (default name, like "Makefile" for GNU Make, is "build.xml") contain a list of targets. A target itself contains a list of tasks.
  • A task is anything Ant can do: it can launch a Java compilation, copy files to a directory, and LOTS of other stuff.

Hints & Tips

  • To import another file from a first one, you can use the import task:
<import file="configuration.ant.xml"/>

In this case, the imported file must be a valid Ant XML file. You can also (more easily) just include a list of properties from a file directly with the property task.

  • To be able to reference a variable and expand it (eg, for ${DeploymentDirectory} to be replaced by /var/www/), you must use a property (here, with the name "DeploymentDirectory"). It won't work if you try to reference an XML node, for example.