Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

<groovyc>

Description

Compiles groovy Groovy source files and, if the joint compilation option is used, Java source files.

Required taskdef

Assuming groovy-all-VERSION.jar is in my.classpath you will need to declare this task at some point in the build.xml prior to using this the groovyc task being invoked.

Code Block
<taskdef name="groovyc"
         classname="org.codehaus.groovy.ant.Groovyc"
         classpathref="my.classpath"/>

...

Attribute

Description

Required

srcdir

directories containing Groovy Location of the Groovy (and possibly Java) source files.

Yes

destdir

directory used Location to store the compiled groovy class files.

Yes

classpath

classpath used for compilation

No

The classpath to use.

No

classpathref

The classpath to use given as a path references.

No

sourcepath

The sourcepath to use.

No

sourcepathref

The sourcepath to use given as a path reference.

No

encoding

Encoding of source files.

No

verbose

Asks the compiler for verbose output; defaults to no.

No

includeAntRuntime

Whether to include the Ant run-time libraries in the classpath; defaults to yes.

No

includeJavaRuntime

Whether to include the default run-time libraries from the executing VM in the classpath; defaults to no.

No

fork

Whether to execute groovyc using a spawned instance of the JVM; defaults to no.

No

memoryInitialSize

The initial size of the memory for the underlying VM, if using fork mode; ignored otherwise. Defaults to the standard VM memory setting. (Examples: 83886080, 81920k, or 80m)

No

memoryMaximumSize

The maximum size of the memory for the underlying VM, if using fork mode; ignored otherwise. Defaults to the standard VM memory setting. (Examples: 83886080, 81920k, or 80m)

No

failonerror

Indicates whether compilation errors will fail the build; defaults to true.

No

listfiles

Indicates whether the source files to be compiled will be listed; defaults to no.

No

stacktrace

if true each compile error message will contain a stacktrace

No

encoding

encoding of source files

No

jointCompilationOptions

enables Enable joint compilation, specifying the command line options. (Using a nested javac task is preferred.)

No

Notes: joint Compilation Joint compilation is only available since 1.1-beta-2

<groovyc> Nested Elements

...

  • For path structures see for example http://ant.apache.org/manual/using.html#path
  • For usages of the javac task see http://ant.apache.org/manual/CoreTasks/javac.html
  • unlike the ant documentation implies the javac task nested in groovyc means that sources, classpaths, destination and the encoding will be taken from the groovyc element. If you still specify sources or classpaths then they will be additional. You should not overwrite the destination, but you are free to choose a different encodingThe nested javac task behaves more or less as documented for the top-level javac task. srcdir, destdir, classpath, encoding for the nested javac task are taken from the enclosing groovyc task. If these attributes are specified then they are added, they do not replace. In fact, you should not attempt to overwrite the destination. Other attributes and nested elements are unaffected, for example fork and maxmem , memoryMaximumSize, etc. may be used freely.

Joint Compilation

Joint Compilation compilation means that the groovy Groovy compilation will parse the groovy Groovy source files, create a stub of these, will use a java stubs for all of them, invoke the Java compiler to compile the stubs along with java Java sources, and then continue compilation in the normal groovy Groovy compiler way. This allows to mix java and groovy files freely in most casesmixing of Java and Groovy files without constraint.

To use invoke joint compilation with the jointCompilationOptions Attributeattribute, you have to simulate the command line with compiler switches. -j will enable enables the joint compilation , every option with -F can be used for flags like nowarn (example -Fnowarn), options with values can be used with -J and an = like for mode of working. Flags to the Java compiler are presented to the Groovy compiler with the -F option. So, for example, flags like nowarn are specified with -Fnowarn. Options to the Java compiler that take values are presented to the Groovy compiler using -J options. For example -Jtarget=1.4 -Jsource=1.4 . Using the attribute means to use the javac compiler provided by sun. A complete is used to specify the target level and source level. So a complete joinCompilationOptions value may look for example like this: "-j -Fnowarn -Jtarget=1.4 -J-source=1.4"
The other way is to use the javac nested element. You can there use any attribute or nested element javac allows as. The compiler used here will be the one ant selects. If you told ant to use for example jikes as java compiler, then this javac will use jikes too. If you use the nested javac element, you don't need to use the attribute. If you still use the attribute, its value will be ignored.Example form build.xml in 1.1 beta-3. Clearly, using this way of specifying things is a real nuisance and not very Ant-like. In fact there are thoughts to deprecate this way of working and remove it as soon as is practical.

The right way of working is, of course, to use a nested tag and all the attributes and further nested tags as required. It is rare to specify srcdir and destdir, the nested javac task is provided with the srcdir and destdir values from the enclosing groovyc task, and it is invariable the right thing to do just to leave this as is. Here is an example:

Code Block
xml
xml
<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>

To restate: the javac task gets the srcdir, destdir and classpath from the enclosing groovyc task.