Java Reference
In-Depth Information
JAR file. Once the groovy task has been defined it can be used to execute arbitrary
Groovy code. A straight print of “Hello, World!” is executed, and then the Ant echo task
is also called.
It's therefore easy enough to add Groovy code to an existing Ant build file, which can be
useful if looping or conditional logic is needed in the build. It's notoriously difficult to
“program” in XML, and technologies that tend that direction (like Ant and XSLT) often
result in awkward, complex build files. Adding Groovy scripting code might help the build
file without modifying the underlying source code.
5.3.2. The <groovyc> Ant task
Say you follow the advice in this topic and decide to add Groovy modules to your imple-
mentation code. If you're still going to build with Ant you'll need a compilation task, sim-
ilar to <javac> , for Groovy. That task is <groovyc> .
The basic <groovyc> task definition is simple enough:
<taskdef name="groovyc"
classname="org.codehaus.groovy.ant.Groovyc"
classpathref="groovy.classpath"/>
The name of the task is <groovyc> , and it's backed by the Groovyc class in the
org.codehaus.groovy.ant package. This class is part of the Groovy Ant JARs ref-
erenced in the earlier build file.
The result of this task definition is that you can compile Groovy classes with <groovyc>
while youcompile Java classes with <javac> .This enforced separation ofcode bases can
lead to difficulties, however, if there are cross dependencies. For example, a Groovy class
may implement a Java interface and reference a Java class, which in turn uses a Groovy
class, and so on.
A good way to resolve these issues is to use the joint-compilation approach. Ant lets you
embed the <javac> task inside the <groovyc> task. The nested tag approach results in
a <groovyc> task that looks like this:
Search WWH ::




Custom Search