Java Reference
In-Depth Information
<groovyc srcdir="${src.dir}" destdir="${classes.dir}"
classpathref="classpath">
<javac source="1.5" target="1.5" />
</groovyc>
The nested <javac> task doesn't imply the Java compiler is running. As a child of the
<groovyc> task it lets the Groovy joint compiler do all the work.
The source directory, destination directory, and classpath variables defined in the
<groovyc> task are passed down to the nested <javac> task. The joint-compilation ap-
proach means that Groovy will compile the Groovy sources and create stubs for them, then
call the Java compiler to do the same for the Java sources, and resume the compilation pro-
cess with the Groovy compiler. The result is that you can mix Java and Groovy sources
without a problem.
Therefore, to extend the Ant build file presented section 5.2 to include Groovy files, make
the additions and changes shown in the next listing.
Listing 5.4. Extending the “Hello, World” build to mix Java and Groovy sources
<path id="groovy.classpath">
<fileset dir="${env.GROOVY_HOME}/embeddable" />
</path>
<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar" />
</path>
<taskdef name="groovyc"
classname="org.codehaus.groovy.ant.Groovyc"
classpathref="groovy.classpath" />
...
<target name="compile">
<mkdir dir="${classes.dir}" />
<groovyc srcdir="${src.dir}" destdir="${classes.dir}"
classpathref="classpath">
<javac source="1.5" target="1.5" />
</groovyc>
</target>
The rest is the same as before.
Search WWH ::




Custom Search