5

I have to include Groovy classes into existing Java apps, and include Groovy into Ant's build.xml file.

What is the best way to configure Ant's build.xml for it?

Update: Are there more specifics in combining Java and Groovy compilations? Sequence of tasks?

Jason Plank
  • 2,336
  • 5
  • 31
  • 40
Tatyana Solovyeva
  • 231
  • 1
  • 5
  • 8

3 Answers3

2

@VonC is correct about including Groovy scripting in your Ant build.

To expand a bit:

To compile .groovy and .java sources together for use in the same application, use the <groovyc> Ant task.

See Ant Integration with Groovy for the reference.

Ken Gentle
  • 13,277
  • 2
  • 41
  • 49
1

To use Groovy in your ant script, you basically have to declare the Groovy ant task:

<project name="groovy-build" default="listSourceFiles">

<taskdef name="groovy"
     classname="org.codehaus.groovy.ant.Groovy"/>
<groovy>
    ant.... // some ant groovy directives
</groovy>
</target>
</project>

However, you have to be careful, in your ant.xml, to refer to fileset within your current target.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

You should define javac inside groovyc, like this.

<groovyc srcdir="${testSourceDirectory}" destdir="${testClassesDirectory}">
  <classpath>
    <pathelement path="${mainClassesDirectory}"/>
    <pathelement path="${testClassesDirectory}"/>
    <path refid="testPath"/>
  </classpath>
  <javac source="1.4" target="1.4" debug="on" />
</groovyc>

For more info have a look here: http://groovy.codehaus.org/The+groovyc+Ant+Task at section Joint Compilation.

Ondrej Kvasnovsky
  • 4,592
  • 3
  • 30
  • 40