Ant Hacks by Erik Hatcher
The first session I attended was Erik Hatcher's Ant Hacks talk. The first half of his talk was about Ant in general and was most of the stuff covered in Java Development with Ant. The good stuff was the 2nd half when he covered all the new stuff in Ant 1.6. Steve is working on an update to Java Development with Ant - shoujld will be a lot thinner. Below are some notes I took on what's new in 1.6.
- <image> task. Requires Java Advanced Imaging API
- Performs image manipulation
- <import> task
- No more entity ref includes needed - can use Ant properties for file reference now.
- OO Nature
- mix in imported build files - call super on imported file by specifying depends="${ant.project.name}.target" where the project.name is specified in the imported build file. Only targets that are overridden will get prefixed with namespace.
- target overriding - main build file takes precedence
- "abstract" targets - requires main build file implementation
- <subant> task - Recurses tree
- Two modes: 1) same build file in each sub directory 2) crawl a tree and run same build file on all subdirectories
- Can have targetless build files. Everything outside a target gets executed before any targets
- <presetdef> - Use the same task and optionally repeat. Define the options once, give it a name and refer to it later. Can override attributes later in the build.xml file. Only works for one task at a time.
- <macrodef> - bye bye antcall. Much faster than antcall - does all the
same things
- You can specify attributes and elements as part of the definition.
Tasks are wrapped in a <sequential> tag.
- attributes are referred to in tasks using @{attribute}
- elements are simple placeholders using XML <element/>
- I could really use this stuff in AppFuse to replace the compile-module and test-module targets
- "spawn" a new attribute on <java> - allows process to live past when Ant dies
- You can specify attributes and elements as part of the definition.
Tasks are wrapped in a <sequential> tag.
- <scriptdef> - allows you to use all kinds of scripting languages - i.e.
Groovy, JavaScript, etc.
- the project, attributes and elements are given to you - so you can easily grab them in the scripts
- helpful to know Ant's API when writing
- <antlib> - componentizes definition of types and tasks
- anything that defines stuff - put in antlib.xml (i.e. <taskdef>)
- mostly designed for Ant task distributors because they can package an antlib.xml with a namespace
- has root element
of <antlib> instead of XML
- xmlns:antcontrib="antlib:net.sf.antcontrib" - brings in all tasks into your project
I really liked Erik's talk because AppFuse was inspired by his Java Development
with Ant book. Its build.xml file was intially based on Erik's sample app
and therefore, the first half of his talk pretty much pointed out tips and
tricks that I'm currently using. The 2nd half of his talk was highlighting
the new features of 1.6 - which he's suggested I adopt in the past. I've
never had much desire (or time) to dig in and update AppFuse's build.xml
file to 1.6. However, after attending his talk - it seems like it should
be pretty easy to do. Good bye <antcall>, hello <macrodef>.
Later: One of the coolest things I saw in Erik's talk was how his Ant logging was color coded. I asked him about it and all your need to do is specify "-logger org.apache.tools.ant.listener.AnsiColorLogger" in an ANT_ARGS environment variable. Good stuff!
Posted by Eric Hauser on November 18, 2004 at 05:58 PM MST #