Skip to end of metadata
Go to start of metadata

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 fileScanner
  • 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 ...

Using the joint compiler

Here is a small build file which uses the joint compiler to compile Groovy and Java source files together, and put them in WEB-INF/classes:


  1. Here are a few other examples:

    • Starting AntBuilder with a basedir pointing at a specific directorydef ant = new AntBuilder()
      ant.project.setProperty('basedir', 'mypath')
    • Using Ant propeties in the groovy code that called AntBuilderdef ant = new AntBuilder()'foo', value:'bar')
  2. Thanks for your guide for us, it is very useful. It's very important that what you write and what you want to exactly say, you show me some of the relevant information that i need. I tried some shared info sources  but neither was giving enough details about it.

  3. Can you please put up some kind of documentation on how to get something like flexTasks to run using a groovy script.

    Thank you.