If ever you've been working with a build.xml file or some Jelly script and found yourself a little restricted by all those pointy brackets, or found it a bit wierd using XML as a scripting language and wanted something a little cleaner and more straight forward, then maybe Ant scripting with Groovy might be what you're after.
Groovy has a helper class called
AntBuilder which makes 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. Ant itself is a collection of jar files. By adding them to your classpath, you can easily use them within Groovy as is. We believe using
AntBuilder leads to more concise and readily understood syntax.
Below are some examples (most taken from Groovy's own AntBuilder tests) which demonstrate:
- the use of Ant inside Groovy using the AntBuilder DSL notation
- a demo of iterating through an Ant FileSet using
- that normal variables can be used to pass state into the Ant tasks and that Groovy code can be embedded anywhere in the markup.
Compiling and running a Java file:
Sniffing around ...