Class Groovyc
- All Implemented Interfaces:
- Cloneable,- org.apache.tools.ant.types.selectors.SelectorContainer
Typically involves using Ant from the command-line and an Ant build file such as:
 <?xml version="1.0"?>
 <project name="MyGroovyBuild" default="compile">
   <property name="groovy.home" location="/Path/To/Groovy"/>
   <property name="groovy.version" value="X.Y.Z"/>
   <taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc">
     <classpath>
       <fileset file="${groovy.home}/lib/groovy-${groovy.version}.jar"/>
       <fileset file="${groovy.home}/lib/groovy-ant-${groovy.version}.jar"/>
     </classpath>
   </taskdef>
   <target name="compile" description="compile groovy sources">
     <groovyc srcdir="src" destdir="bin" fork="true" listfiles="true" includeantruntime="false">
       <classpath>
         <fileset dir="${groovy.home}/lib" includes="groovy-*${groovy.version}.jar" excludes="groovy-ant-${groovy.version}.jar"/>
       </classpath>
     </groovyc>
   </target>
 </project>
 
 This task can take the following arguments:
- srcdir
- destdir
- sourcepath
- sourcepathRef
- classpath
- classpathRef
- scriptExtension
- targetBytecode
- listfiles
- failonerror
- proceed
- memoryInitialSize
- memoryMaximumSize
- encoding
- verbose
- includeantruntime
- includejavaruntime
- fork
- javaHome
- executable
- updatedProperty
- errorProperty
- includeDestClasses
- jointCompilationOptions
- stacktrace
- scriptBaseClass
- stubdir
- keepStubs
- forceLookupUnnamedFiles
- configscript
- parameters
- javac
When this task executes, it will recursively scan srcdir and destdir looking for Groovy source files to compile. This task makes its compile decision based on timestamp.
A more elaborate build file showing joint compilation:
 <?xml version="1.0"?>
 <project name="MyJointBuild" default="compile">
   <property name="groovy.home" location="/Path/To/Groovy"/>
   <property name="groovy.version" value="X.Y.Z"/>
   <path id="classpath.main">
     <fileset dir="${groovy.home}/lib">
       <include name="groovy-*${groovy.version}.jar"/>
       <exclude name="groovy-ant-${groovy.version}.jar"/>
     </fileset>
   </path>
   <taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc">
     <classpath>
       <fileset file="${groovy.home}/lib/groovy-${groovy.version}.jar"/>
       <fileset file="${groovy.home}/lib/groovy-ant-${groovy.version}.jar"/>
     </classpath>
   </taskdef>
   <target name="clean">
     <delete dir="bin" failonerror="false"/>
   </target>
   <target name="compile" depends="clean" description="compile java and groovy sources">
     <mkdir dir="bin"/>
     <groovyc srcdir="src" destdir="bin" stubdir="stubs" keepStubs="true"
      fork="true" includeantruntime="false" classpathref="classpath.main">
       <javac debug="true" source="1.8" target="1.8"/>
     </groovyc>
   </target>
 </project>
 
 Based on the implementation of the Javac task in Apache Ant.
 Can also be used from AntBuilder to allow the build file to be scripted in Groovy.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected File[]protected CompilerConfigurationprotected booleanprotected booleanFields inherited from class org.apache.tools.ant.taskdefs.MatchingTaskfilesetFields inherited from class org.apache.tools.ant.Tasktarget, taskName, taskType, wrapperFields inherited from class org.apache.tools.ant.ProjectComponentdescription, location, project
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddConfiguredJavac(org.apache.tools.ant.taskdefs.Javac javac) Add the configured nested javac task if present to initiate joint compilation.protected voidaddToCompileList(File[] newFiles) protected GroovyClassLoaderprotected voidprotected voidcompile()org.apache.tools.ant.types.PathAdds a path to the classpath.org.apache.tools.ant.types.PathAdds a path to sourcepath.org.apache.tools.ant.types.PathAdds a path for source compilation.voidexecute()Executes the task.org.apache.tools.ant.types.PathGets the classpath to be used for this compilation.Get the configuration file used to customize the compilation configuration.Gets the destination directory into which the java source files should be compiled.Returns the encoding to be used when creating files.The value of the executable attribute, if any.booleanGets the failonerror flag.File[]Gets the list of files to be compiled.booleanGets the forceLookupUnnamedFiles flag.booleanGets whether the ant classpath is to be included in the classpath.booleanGets whether the java runtime should be included in this task's classpath.booleangetIndy()Deprecated.booleanGets the keepStubs flag.booleanGet the listfiles flag.Gets the memoryInitialSize flag.Gets the memoryMaximumSize flag.booleanReturns true if parameter metadata generation has been enabled.booleanReturns true if preview features has been enabled.Get the base script class name for the scripts (must derive from Script)Get the extension to use when searching for Groovy source files.org.apache.tools.ant.types.PathGets the sourcepath to be used for this compilation.org.apache.tools.ant.types.PathGets the source dirs to find the source java files.Gets the stub directory into which the Java source stub files should be generatedRetrieves the compiler bytecode compatibility level.booleanGet the result of the groovyc task (success or failure).booleanGets the verbose flag.booleanGet the value of the includeDestClasses property.protected CompilationUnitDeprecated.This method is not in use anymore.protected CompilationUnitmakeCompileUnit(GroovyClassLoader loader) protected org.apache.tools.ant.types.PathRecreate src.protected voidClear the list of files to be compiled and copied.protected voidScans the directory looking for source files to be compiled.voidsetClasspath(org.apache.tools.ant.types.Path classpath) Set the classpath to be used for this compilation.voidsetClasspathRef(org.apache.tools.ant.types.Reference r) Adds a reference to a classpath defined elsewhere.voidsetConfigscript(String configscript) Set the configuration file used to customize the compilation configuration.voidsetDestdir(File destDir) Set the destination directory into which the Java source files should be compiled.voidsetEncoding(String encoding) Sets the file encoding for generated files.voidsetErrorProperty(String errorProperty) The property to set on compilation failure.voidsetExecutable(String forkExecPath) Sets the name of the java executable to use when invoking the compiler in forked mode, ignored otherwise.voidsetFailonerror(boolean fail) Indicates whether the build will continue even if there are compilation errors; defaults to true.voidsetForceLookupUnnamedFiles(boolean forceLookupUnnamedFiles) Set the forceLookupUnnamedFiles flag.voidsetFork(boolean f) If true forks the Groovy compiler.voidsetIncludeantruntime(boolean include) If true, includes Ant's own classpath in the classpath.voidsetIncludeDestClasses(boolean includeDestClasses) This property controls whether to include the destination classes directory in the classpath given to the compiler.voidsetIncludejavaruntime(boolean include) If true, includes the Java runtime libraries in the classpath.voidsetIndy(boolean indy) Deprecated.voidsetJavaHome(File home) The JDK Home to use when forked.voidsetKeepStubs(boolean keepStubs) Set the keepStubs flag.voidsetListfiles(boolean list) If true, list the source files being handed off to the compiler.voidsetMemoryInitialSize(String memoryInitialSize) The initial size of the memory for the underlying VM if javac is run externally; ignored otherwise.voidsetMemoryMaximumSize(String memoryMaximumSize) The maximum size of the memory for the underlying VM if javac is run externally; ignored otherwise.voidsetParameters(boolean parameters) If true, generates metadata for reflection on method parameter names (jdk8+ only).voidsetPreviewFeatures(boolean previewFeatures) If true, enable preview Java features (JEP 12) (jdk12+ only).voidsetProceed(boolean proceed) voidsetScriptBaseClass(String scriptBaseClass) Set the base script class name for the scripts (must derive from Script)voidsetScriptExtension(String scriptExtension) Set the extension to use when searching for Groovy source files.voidsetSourcepath(org.apache.tools.ant.types.Path sourcepath) Set the sourcepath to be used for this compilation.voidsetSourcepathRef(org.apache.tools.ant.types.Reference r) Adds a reference to a source path defined elsewhere.voidsetSrcdir(org.apache.tools.ant.types.Path srcDir) Set the source directories to find the source Java files.voidsetStacktrace(boolean stacktrace) Enable compiler to report stack trace information if a problem occurs during compilation.voidsetStubdir(File stubDir) Set the stub directory into which the Java source stub files should be generated.voidsetTargetBytecode(String version) Sets the bytecode compatibility level.voidsetUpdatedProperty(String updatedProperty) The property to set on compilation success.voidsetVerbose(boolean verbose) Enable verbose compiling which will display which files are being compiled.Methods inherited from class org.apache.tools.ant.taskdefs.MatchingTaskadd, addAnd, addContains, addContainsRegexp, addCustom, addDate, addDepend, addDepth, addDifferent, addFilename, addMajority, addModified, addNone, addNot, addOr, addPresent, addSelector, addSize, addType, appendSelector, createExclude, createExcludesFile, createInclude, createIncludesFile, createPatternSet, getDirectoryScanner, getImplicitFileSet, getSelectors, hasSelectors, selectorCount, selectorElements, setCaseSensitive, setDefaultexcludes, setExcludes, setExcludesfile, setFollowSymlinks, setIncludes, setIncludesfile, setProject, XsetIgnore, XsetItemsMethods inherited from class org.apache.tools.ant.TaskbindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskTypeMethods inherited from class org.apache.tools.ant.ProjectComponentclone, getDescription, getLocation, getProject, setDescription, setLocation
- 
Field Details- 
failOnErrorprotected boolean failOnError
- 
listFilesprotected boolean listFiles
- 
compileList
- 
configuration
 
- 
- 
Constructor Details- 
Groovycpublic Groovyc()
 
- 
- 
Method Details- 
createSrcpublic org.apache.tools.ant.types.Path createSrc()Adds a path for source compilation.- Returns:
- a nested src element.
 
- 
recreateSrcprotected org.apache.tools.ant.types.Path recreateSrc()Recreate src.- Returns:
- a nested src element.
 
- 
setSrcdirpublic void setSrcdir(org.apache.tools.ant.types.Path srcDir) Set the source directories to find the source Java files.- Parameters:
- srcDir- the source directories as a path
 
- 
getSrcdirpublic org.apache.tools.ant.types.Path getSrcdir()Gets the source dirs to find the source java files.- Returns:
- the source directories as a path
 
- 
setScriptExtensionSet the extension to use when searching for Groovy source files. Accepts extensions in the form *.groovy, .groovy or groovy- Parameters:
- scriptExtension- the extension of Groovy source files
 
- 
getScriptExtensionGet the extension to use when searching for Groovy source files.- Returns:
- the extension of Groovy source files
 
- 
setTargetBytecodeSets the bytecode compatibility level. The parameter can take one of the values inCompilerConfiguration.ALLOWED_JDKS.- Parameters:
- version- the bytecode compatibility level
 
- 
getTargetBytecodeRetrieves the compiler bytecode compatibility level.- Returns:
- bytecode compatibility level. Can be one of the values in CompilerConfiguration.ALLOWED_JDKS.
 
- 
setDestdirSet the destination directory into which the Java source files should be compiled.- Parameters:
- destDir- the destination director
 
- 
getDestdirGets the destination directory into which the java source files should be compiled.- Returns:
- the destination directory
 
- 
setSourcepathpublic void setSourcepath(org.apache.tools.ant.types.Path sourcepath) Set the sourcepath to be used for this compilation.- Parameters:
- sourcepath- the source path
 
- 
getSourcepathpublic org.apache.tools.ant.types.Path getSourcepath()Gets the sourcepath to be used for this compilation.- Returns:
- the source path
 
- 
createSourcepathpublic org.apache.tools.ant.types.Path createSourcepath()Adds a path to sourcepath.- Returns:
- a sourcepath to be configured
 
- 
setSourcepathRefpublic void setSourcepathRef(org.apache.tools.ant.types.Reference r) Adds a reference to a source path defined elsewhere.- Parameters:
- r- a reference to a source path
 
- 
setClasspathpublic void setClasspath(org.apache.tools.ant.types.Path classpath) Set the classpath to be used for this compilation.- Parameters:
- classpath- an Ant Path object containing the compilation classpath.
 
- 
getClasspathpublic org.apache.tools.ant.types.Path getClasspath()Gets the classpath to be used for this compilation.- Returns:
- the class path
 
- 
createClasspathpublic org.apache.tools.ant.types.Path createClasspath()Adds a path to the classpath.- Returns:
- a class path to be configured
 
- 
setClasspathRefpublic void setClasspathRef(org.apache.tools.ant.types.Reference r) Adds a reference to a classpath defined elsewhere.- Parameters:
- r- a reference to a classpath
 
- 
setListfilespublic void setListfiles(boolean list) If true, list the source files being handed off to the compiler. Default is false.- Parameters:
- list- if true list the source files
 
- 
getListfilespublic boolean getListfiles()Get the listfiles flag.- Returns:
- the listfiles flag
 
- 
setFailonerrorpublic void setFailonerror(boolean fail) Indicates whether the build will continue even if there are compilation errors; defaults to true.- Parameters:
- fail- if true halt the build on failure
 
- 
setProceedpublic void setProceed(boolean proceed) - Parameters:
- proceed- inverse of failonerror
 
- 
getFailonerrorpublic boolean getFailonerror()Gets the failonerror flag.- Returns:
- the failonerror flag
 
- 
setMemoryInitialSizeThe initial size of the memory for the underlying VM if javac is run externally; ignored otherwise. Defaults to the standard VM memory setting. (Examples: 83886080, 81920k, or 80m)- Parameters:
- memoryInitialSize- string to pass to VM
 
- 
getMemoryInitialSizeGets the memoryInitialSize flag.- Returns:
- the memoryInitialSize flag
 
- 
setMemoryMaximumSizeThe maximum size of the memory for the underlying VM if javac is run externally; ignored otherwise. Defaults to the standard VM memory setting. (Examples: 83886080, 81920k, or 80m)- Parameters:
- memoryMaximumSize- string to pass to VM
 
- 
getMemoryMaximumSizeGets the memoryMaximumSize flag.- Returns:
- the memoryMaximumSize flag
 
- 
setEncodingSets the file encoding for generated files.- Parameters:
- encoding- the file encoding to be used
 
- 
getEncodingReturns the encoding to be used when creating files.- Returns:
- the file encoding to use
 
- 
setVerbosepublic void setVerbose(boolean verbose) Enable verbose compiling which will display which files are being compiled. Default is false.
- 
getVerbosepublic boolean getVerbose()Gets the verbose flag.- Returns:
- the verbose flag
 
- 
setIncludeantruntimepublic void setIncludeantruntime(boolean include) If true, includes Ant's own classpath in the classpath. Default is true. If setting to false and using groovyc in conjunction with AntBuilder you might need to explicitly add the Groovy jar(s) to the groovyc classpath using a nested classpath task.- Parameters:
- include- if true, includes Ant's own classpath in the classpath
 
- 
getIncludeantruntimepublic boolean getIncludeantruntime()Gets whether the ant classpath is to be included in the classpath.- Returns:
- whether the ant classpath is to be included in the classpath
 
- 
setIncludejavaruntimepublic void setIncludejavaruntime(boolean include) If true, includes the Java runtime libraries in the classpath. Default is false.- Parameters:
- include- if true, includes the Java runtime libraries in the classpath
 
- 
getIncludejavaruntimepublic boolean getIncludejavaruntime()Gets whether the java runtime should be included in this task's classpath.- Returns:
- the includejavaruntime attribute
 
- 
setForkpublic void setFork(boolean f) If true forks the Groovy compiler. Default is false.- Parameters:
- f- "true|false|on|off|yes|no"
 
- 
setJavaHomeThe JDK Home to use when forked. Ignored if "executable" is specified.- Parameters:
- home- the java.home value to use, default is the current JDK's home
 
- 
setExecutableSets the name of the java executable to use when invoking the compiler in forked mode, ignored otherwise.- Parameters:
- forkExecPath- the name of the executable
- Since:
- Groovy 1.8.7
 
- 
getExecutableThe value of the executable attribute, if any.- Returns:
- the name of the java executable
- Since:
- Groovy 1.8.7
 
- 
setUpdatedPropertyThe property to set on compilation success. This property will not be set if the compilation fails, or if there are no files to compile.- Parameters:
- updatedProperty- the property name to use.
 
- 
setErrorPropertyThe property to set on compilation failure. This property will be set if the compilation fails.- Parameters:
- errorProperty- the property name to use.
 
- 
setIncludeDestClassespublic void setIncludeDestClasses(boolean includeDestClasses) This property controls whether to include the destination classes directory in the classpath given to the compiler. The default value is "true".- Parameters:
- includeDestClasses- the value to use.
 
- 
isIncludeDestClassespublic boolean isIncludeDestClasses()Get the value of the includeDestClasses property.- Returns:
- the value.
 
- 
getTaskSuccesspublic boolean getTaskSuccess()Get the result of the groovyc task (success or failure).- Returns:
- true if compilation succeeded, or was not necessary, false if the compilation failed.
 
- 
addConfiguredJavacpublic void addConfiguredJavac(org.apache.tools.ant.taskdefs.Javac javac) Add the configured nested javac task if present to initiate joint compilation.
- 
setStacktracepublic void setStacktrace(boolean stacktrace) Enable compiler to report stack trace information if a problem occurs during compilation. Default is false.
- 
setIndyDeprecated.Legacy method to set the indy flag (only true is allowed)- Parameters:
- indy- true means invokedynamic support is active
 
- 
getIndyDeprecated.Get the value of the indy flag (always true).
- 
setScriptBaseClassSet the base script class name for the scripts (must derive from Script)- Parameters:
- scriptBaseClass- Base class name for scripts (must derive from Script)
 
- 
getScriptBaseClassGet the base script class name for the scripts (must derive from Script)- Returns:
- Base class name for scripts (must derive from Script)
 
- 
getConfigscriptGet the configuration file used to customize the compilation configuration.- Returns:
- a path to a configuration script
 
- 
setConfigscriptSet the configuration file used to customize the compilation configuration.- Parameters:
- configscript- a path to a configuration script
 
- 
setStubdirSet the stub directory into which the Java source stub files should be generated. The directory need not exist and will not be deleted automatically - though its contents will be cleared unless 'keepStubs' is true. Ignored when forked.- Parameters:
- stubDir- the stub directory
 
- 
getStubdirGets the stub directory into which the Java source stub files should be generated- Returns:
- the stub directory
 
- 
setKeepStubspublic void setKeepStubs(boolean keepStubs) Set the keepStubs flag. Defaults to false. Set to true for debugging. Ignored when forked.- Parameters:
- keepStubs- should stubs be retained
 
- 
getKeepStubspublic boolean getKeepStubs()Gets the keepStubs flag.- Returns:
- the keepStubs flag
 
- 
setForceLookupUnnamedFilespublic void setForceLookupUnnamedFiles(boolean forceLookupUnnamedFiles) Set the forceLookupUnnamedFiles flag. Defaults to false.The Groovyc Ant task is frequently used in the context of a build system that knows the complete list of source files to be compiled. In such a context, it is wasteful for the Groovy compiler to go searching the classpath when looking for source files and hence by default the Groovyc Ant task calls the compiler in a special mode with such searching turned off. If you wish the compiler to search for source files then you need to set this flag to true.- Parameters:
- forceLookupUnnamedFiles- should unnamed source files be searched for on the classpath
 
- 
getForceLookupUnnamedFilespublic boolean getForceLookupUnnamedFiles()Gets the forceLookupUnnamedFiles flag.- Returns:
- the forceLookupUnnamedFiles flag
 
- 
setParameterspublic void setParameters(boolean parameters) If true, generates metadata for reflection on method parameter names (jdk8+ only). Defaults to false.- Parameters:
- parameters- set to true to generate metadata.
 
- 
getParameterspublic boolean getParameters()Returns true if parameter metadata generation has been enabled.
- 
setPreviewFeaturespublic void setPreviewFeatures(boolean previewFeatures) If true, enable preview Java features (JEP 12) (jdk12+ only).- Parameters:
- previewFeatures- set to true to enable preview features
 
- 
getPreviewFeaturespublic boolean getPreviewFeatures()Returns true if preview features has been enabled.
- 
executepublic void execute() throws org.apache.tools.ant.BuildExceptionExecutes the task.- Overrides:
- executein class- org.apache.tools.ant.Task
- Throws:
- org.apache.tools.ant.BuildException- if an error occurs
 
- 
resetFileListsprotected void resetFileLists()Clear the list of files to be compiled and copied.
- 
scanDirScans the directory looking for source files to be compiled. The results are returned in the class variable compileList- Parameters:
- srcDir- The source directory
- destDir- The destination directory
- files- An array of filenames
 
- 
addToCompileList
- 
getFileListGets the list of files to be compiled.- Returns:
- the list of files as an array
 
- 
checkParametersprotected void checkParameters() throws org.apache.tools.ant.BuildException- Throws:
- org.apache.tools.ant.BuildException
 
- 
compileprotected void compile()
- 
makeCompileUnitDeprecated.This method is not in use anymore. UsemakeCompileUnit(GroovyClassLoader)instead.
- 
makeCompileUnit
- 
buildClassLoaderFor
 
-