login

Ant and Gant

Using Ant from Gant

While most of how Ant tasks are translated into Gant scripts is covered by the AntBuilder documentation I'll just give a brief description here.

When translating the syntax of an Ant task the task name become the function that is called.

So the echo task <echo/> becomes just echo.

Attributes on the task XML element become named parameters in the method call.

So <echo message="Hello" /> becomes echo(message: "Hello").

Child elements of a task element become calls inside a closure that is called on the target.

So for example:

<javac srcdir="src>
    <classpath>
         <file dir="lib">
             <include name="*.jar" />
        </file>
    </classpath>
</javac>

Becomes the much more concise:

javac(srcdir: "src") {
    classpath {
        file(dir: "lib") { include( name: '*.jar' }
    }
}

So when you see attributes: think named parameters.

When you see nested elements think calls inside closures.