Java Reference
In-Depth Information
The following subsections will tackle each of these Groovy and Ant topics in turn.
5.3.1. The <groovy> Ant task
Ant has two hooks that allow you to add Groovy to a standard build file. The
<groovy>
and
<groovyc>
tasks use the Groovy libraries to execute Groovy scripts and compile
Groovy source files, respectively.
Starting first with
<groovy>
, defining the associated task in an Ant build lets you write
Groovy code directly into the build file. The following listing shows a trivial example.
Listing 5.3. A trivial Ant build that executes Groovy code in a task
The
environment
property allows the build to access system properties in the operating
system. Here the
env
variable is used to access the current value of
GROOVY_HOME
, the
installation directory for Groovy. The
<path>
element assigns the groovy-all JAR file
(found in the embeddable directory) to the
groovy.classpath
ID.
The
<taskdef>
element then defines the
groovy
task as a reference to the
org.codehaus.groovy.ant.Groovy
class, which is resolved in the groovy-all