With a new release of Java-based build tool Ant approaching, Kev Jackson provides a
tutorial on using antlibs, a new feature that helps create and distribute custom Ant tasks, types, and macros, and distribute the optional tasks included with the Ant distribution.
According to Jackson, antlibs are a solution to problems presented by taskdefs, including classpath lookups, distributing custom tasks and tight coupling of optional tasks.
- By default, antlibs are placed in $ANT_HOME/lib and specified using XML namespaces.
- The antlib format provides a good standard method of distribution (single .jar containing tasks, types, and macros, together with an XMLdescriptor).
- Optional tasks can be de-coupled from the Ant core code and released on a different schedule.
The antlib feature allows developers of Ant tasks to ship fixes and updates independently of the main Ant distribution.
An antlib is simply a collection of classes bundled with an XML descriptor file. Typically, an antlib is distributed as a .jar file, but this isn't a strict requirement. The root element of the XML file is . Any classes can go into the makeup of an antlib, but only some classes can be declared in the antlib.xml file.
Jackson also describes the AntUnit antlib, a quicker method of creating unit tests for Ant tasks.
Another new facility provided by Ant is the AntUnit antlib. Unlike a JUnit TestCase or a BuildFileTest, AntUnit allows you to specify your tests without using any Java code.
Jackson goes on to write the start of an antlib for the SCM system Arch to show how to develop new tasks with the antlib mechanism. He also tests this antlib with an AntUnit test.
What do you think of these soon-to-be-available features?