Ant’s Task Model

Understanding custom tasks means understanding the task model. Ant, being a Java-based program, uses Java’s class hierarchy and reflection capabilities to perform its duties. All Ant tasks derive, directly or indirectly, from the abstract class org.apache.tools.ant.Task. The Ant engine manages all task objects at this level, manipulating only Task objects. For the engine, every task derives from the same class and has the same core methods and properties as every other task. The combination of XML parsing and a method-naming scheme allows Ant to use all of Task’s subclasses. Additionally, Ant processes tasks in a fixed manner — in other words, Ant processes every task in a cycle. While understanding this model and process in detail is not a requirement to writing simple tasks, complex tasks may exhibit undesirable behaviors unless you understand the entire task model and execution process.

The Parts of a Task

A task has two faces. To an Ant end user, a task is nothing more than the XML in a buildfile. ...

Get Ant: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.