After the weekends post on Groovy SQL and GroovyMarkup, here's a little post about scripting Ant tasks.
If ever you've been working with a build.xml or some Jelly
script and found yourself a little restricted by all those pointy
brackets & found it a bit wierd using XML as a scripting language
and wanted something a little cleaner & more straight forward, take
a look at Groovy's Ant scripting support...
inside a Groovy script can make the scripting of Ant tasks really easy;
allowing a real scripting language to be used for programming
constructs (variables, methods, loops, logical branching , classes
etc). It still looks like a neat concise version of Ant's XML without
all those pointy brackets; though you can mix and match this markup
inside your script.
Here's an example
which is probably my favourite Groovy unit test case so far; in one
simple concise file we have a JUnit test case that demonstrates the use
of Ant inside Groovy along with testing that it actually works along
with a demo of iterating through an Ant FileSet. Notice that normal
variables can be used to pass state into the Ant tasks and that Groovy
code can be embedded anywhere in the markup.
Basically we've just created an XML builder, called AntBuilder, which handles GroovyMarkup and scripts Ant tasks. So we've integrated Ant scripting into Groovy with one fairly simple class.