Substitute for the Javac task with integrated preprocessing.
GppJavac simply inserts a preprocessing step just before compilation that, in effect, treats each source file as a Groovy Template. The preprocessed result is written to a temporary directory (the location of which you may specify) so as not to overwrite the original files.
In addition, GppJavac also inserts an instance of GppTool into the Groovy Template Context that allows you to access information about the source and destination files and encodings used for each file copied. It can be accessed through the key,gpp.
GppJavac may be freely substituted wherever you used javac, but be aware that $ characters must be escaped (use the \ character) or Groovy may try to expand them them.
GppJavac supports all of Javac's parameters in addition to the following:
| Name | Description | Required |
Legal Values ( [] indicates the default, if applicable)
|
|---|---|---|---|
preprocess
|
Turns preprocessing on or off. | No | [Yes], No |
prepdir
|
Sets the directory used for preprocessor output. This directory will be created if it does not exist. | No |
A directory path. [gppjavac.out]
|
keep
|
If yes, then the prepdir
will be deleted upon completion, else
the directory will be deleted.
|
No | Yes |
In addition to all of Javac's parameters, GppJavac also supports all of Javac's parameters specified as nested elements, in addition to the following:
configBy specifying this nested element, you can configure the Groovy Template Engine and Context used when preprocessing. See GppConfig for a detailed description.
gpp namespace.
If not using as an antlib, then simply omit the ':' character and the xmlns
attribute.
<gpp:javac
srcdir="${src}"
destdir="build/classes"
classpath="xyz.jar"
/>
first preprocesses then compiles all .java files under the ${src} directory, and stores the .class files in the ${build} directory.
<gpp:javac
srcdir="${src}"
destdir="build/classes"
classpath="xyz.jar"
keep="yes"
prepdir="/temp/gppjavac.out"
preprocess="yes"
/>
preprocesses and compiles as above, but explicity sets the
keep, prepdir and
preprocess attributes.
<gpp:javac
srcdir="${src}"
destdir="build/classes"
classpath="xyz.jar"
xmlns:gpp="antlib:groovytools.ant.gpp"
>
<config>
<context>
<property name="foo" value="bar" />
</context>
</config>
</gpp:javac>
preprocesses and compiles as in the first example, but adds a
Groovy Template Context property called foo.