Package org.codehaus.groovy.control
Class CompilerConfiguration
java.lang.Object
org.codehaus.groovy.control.CompilerConfiguration
Compilation control flags and coordination stuff.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final String[]The valid targetBytecode values.static final intThe ASM API version used when loading/parsing classes and generating proxy adapter classes.static final CompilerConfigurationA convenience for getting a default configuration.static final StringThe default source encoding.static final Stringstatic final StringOptimization Option for enabling attaching groovydoc as AST node metadata.static final StringOptimization Option for enablinginvokedynamiccompilation.JDK version to bytecode version mapping.static final StringDeprecated.static final StringThis ("11") is the value for targetBytecode to compile for a JDK 11.static final StringThis ("12") is the value for targetBytecode to compile for a JDK 12.static final StringThis ("13") is the value for targetBytecode to compile for a JDK 13.static final StringThis ("14") is the value for targetBytecode to compile for a JDK 14.static final StringThis ("15") is the value for targetBytecode to compile for a JDK 15.static final StringThis ("16") is the value for targetBytecode to compile for a JDK 16.static final StringThis ("17") is the value for targetBytecode to compile for a JDK 17.static final StringThis ("18") is the value for targetBytecode to compile for a JDK 18.static final StringThis ("19") is the value for targetBytecode to compile for a JDK 19.static final StringThis ("20") is the value for targetBytecode to compile for a JDK 20.static final StringThis ("21") is the value for targetBytecode to compile for a JDK 21.static final StringThis ("22") is the value for targetBytecode to compile for a JDK 22.static final StringThis ("23") is the value for targetBytecode to compile for a JDK 23.static final StringThis ("24") is the value for targetBytecode to compile for a JDK 24.static final StringThis ("25") is the value for targetBytecode to compile for a JDK 25.static final StringDeprecated.static final StringDeprecated.static final StringDeprecated.static final StringDeprecated.static final StringDeprecated.static final StringDeprecated.static final StringJoint Compilation Option for enabling generating stubs in memory.static final StringOptimization Option for enabling parallel parsing.static final StringOptimization Option for enabling attachingGroovydocannotation.
- 
Constructor SummaryConstructorsConstructorDescriptionSets the compiler flags/settings to default values.CompilerConfiguration(Properties configuration) Sets the configuration flags/settings according to values from the suppliedPropertiesinstance or if not found, supplying a default value.CompilerConfiguration(CompilerConfiguration configuration) Copy constructor.
- 
Method SummaryModifier and TypeMethodDescriptionaddCompilationCustomizers(CompilationCustomizer... customizers) Adds compilation customizers to the compilation process.voidconfigure(Properties configuration) Method to configure a CompilerConfiguration by using Properties.final intReturns the targeted bytecode (aka Java class file) version number.Returns the list of compilation customizers.booleangetDebug()Returns true if debugging operation has been requested.Returns the list of disabled global AST transformation class names.Gets the joint compilation options for this configuration.intReturns stack trace max depth of logging class generationintGets the optimization options for this configuration.Deprecated.not used anymorebooleanReturns true if parameter metadata generation has been enabled.booleanGets the name of the base class for scripts.Gets the currently configured source file encoding.Retrieves the compiler bytecode compatibility level.Gets the target directory for writing classes.intReturns the requested error tolerance.booleanReturns true if verbose operation has been requested.intGets the currently configured warning level.booleanChecks if groovydoc is enabled.booleanChecks if invoke dynamic is enabled.booleanReturns whether logging class generation is enabledstatic booleanisPostJDK10(String bytecodeVersion) Deprecated.static booleanisPostJDK11(String bytecodeVersion) Checks if the specified bytecode version string represents a JDK 11+ compatible bytecode version.static booleanisPostJDK12(String bytecodeVersion) Checks if the specified bytecode version string represents a JDK 12+ compatible bytecode version.static booleanisPostJDK13(String bytecodeVersion) Checks if the specified bytecode version string represents a JDK 13+ compatible bytecode version.static booleanisPostJDK14(String bytecodeVersion) Checks if the specified bytecode version string represents a JDK 14+ compatible bytecode version.static booleanisPostJDK15(String bytecodeVersion) Checks if the specified bytecode version string represents a JDK 15+ compatible bytecode version.static booleanisPostJDK16(String bytecodeVersion) Checks if the specified bytecode version string represents a JDK 16+ compatible bytecode version.static booleanisPostJDK17(String bytecodeVersion) Checks if the specified bytecode version string represents a JDK 17+ compatible bytecode version.static booleanisPostJDK18(String bytecodeVersion) Checks if the specified bytecode version string represents a JDK 18+ compatible bytecode version.static booleanisPostJDK5(String bytecodeVersion) Deprecated.static booleanisPostJDK7(String bytecodeVersion) Deprecated.static booleanisPostJDK8(String bytecodeVersion) Deprecated.static booleanisPostJDK9(String bytecodeVersion) Deprecated.booleanWhether the bytecode version has preview features enabled (JEP 12)booleanChecks if runtime groovydoc is enabled.voidsetBytecodePostprocessor(BytecodeProcessor bytecodePostprocessor) voidsetClasspath(String classpath) Sets the classpath.voidsetClasspathList(List<String> parts) sets the classpath using a list of StringsvoidsetDebug(boolean debug) Turns debugging operation on or off.voidsetDefaultScriptExtension(String defaultScriptExtension) voidsetDisabledGlobalASTTransformations(Set<String> disabledGlobalASTTransformations) Disables the specified global AST transformations.voidsetJointCompilationOptions(Map<String, Object> options) Sets the joint compilation options for this configuration.voidsetLogClassgen(boolean logClassgen) Sets whether logging class generation is enabledvoidsetLogClassgenStackTraceMaxDepth(int logClassgenStackTraceMaxDepth) Sets stack trace max depth of logging class generationvoidsetMinimumRecompilationInterval(int time) voidsetOptimizationOptions(Map<String, Boolean> options) Sets the optimization options for this configuration.voidsetOutput(PrintWriter output) Deprecated.not used anymore, has no effectvoidsetParameters(boolean parameters) Turns parameter metadata generation on or off.voidsetPluginFactory(ParserPluginFactory pluginFactory) voidsetPreviewFeatures(boolean previewFeatures) Sets whether the bytecode version has preview features enabled (JEP 12).voidsetRecompileGroovySource(boolean recompile) voidsetScriptBaseClass(String scriptBaseClass) Sets the name of the base class for scripts.voidsetScriptExtensions(Set<String> scriptExtensions) voidsetSourceEncoding(String encoding) Sets the encoding to be used when reading source files.voidsetTargetBytecode(String version) Sets the bytecode compatibility level.voidsetTargetDirectory(File directory) Sets the target directory.voidsetTargetDirectory(String directory) Sets the target directory.voidsetTolerance(int tolerance) Sets the error tolerance, which is the number of non-fatal errors (per unit) that should be tolerated before compilation is aborted.voidsetVerbose(boolean verbose) Turns verbose operation on or off.voidsetWarningLevel(int level) Sets the warning level.
- 
Field Details- 
INVOKEDYNAMICOptimization Option for enablinginvokedynamiccompilation.- See Also:
 
- 
GROOVYDOCOptimization Option for enabling attaching groovydoc as AST node metadata.- See Also:
 
- 
RUNTIME_GROOVYDOCOptimization Option for enabling attachingGroovydocannotation.- See Also:
 
- 
PARALLEL_PARSEOptimization Option for enabling parallel parsing.- See Also:
 
- 
MEM_STUBJoint Compilation Option for enabling generating stubs in memory.- See Also:
 
- 
JDK4Deprecated.This ("1.4") is the value for targetBytecode to compile for a JDK 1.4.- See Also:
 
- 
JDK5Deprecated.This ("1.5") is the value for targetBytecode to compile for a JDK 1.5.- See Also:
 
- 
JDK6Deprecated.This ("1.6") is the value for targetBytecode to compile for a JDK 1.6.- See Also:
 
- 
JDK7Deprecated.This ("1.7") is the value for targetBytecode to compile for a JDK 1.7.- See Also:
 
- 
JDK8Deprecated.This ("1.8") is the value for targetBytecode to compile for a JDK 1.8.- See Also:
 
- 
JDK9Deprecated.This ("9") is the value for targetBytecode to compile for a JDK 9.- See Also:
 
- 
JDK10Deprecated.This ("10") is the value for targetBytecode to compile for a JDK 10.- See Also:
 
- 
JDK11This ("11") is the value for targetBytecode to compile for a JDK 11.- See Also:
 
- 
JDK12This ("12") is the value for targetBytecode to compile for a JDK 12.- See Also:
 
- 
JDK13This ("13") is the value for targetBytecode to compile for a JDK 13.- See Also:
 
- 
JDK14This ("14") is the value for targetBytecode to compile for a JDK 14.- See Also:
 
- 
JDK15This ("15") is the value for targetBytecode to compile for a JDK 15.- See Also:
 
- 
JDK16This ("16") is the value for targetBytecode to compile for a JDK 16.- See Also:
 
- 
JDK17This ("17") is the value for targetBytecode to compile for a JDK 17.- See Also:
 
- 
JDK18This ("18") is the value for targetBytecode to compile for a JDK 18.- See Also:
 
- 
JDK19This ("19") is the value for targetBytecode to compile for a JDK 19.- See Also:
 
- 
JDK20This ("20") is the value for targetBytecode to compile for a JDK 20.- See Also:
 
- 
JDK21This ("21") is the value for targetBytecode to compile for a JDK 21.- See Also:
 
- 
JDK22This ("22") is the value for targetBytecode to compile for a JDK 22.- See Also:
 
- 
JDK23This ("23") is the value for targetBytecode to compile for a JDK 23.- See Also:
 
- 
JDK24This ("24") is the value for targetBytecode to compile for a JDK 24.- See Also:
 
- 
JDK25This ("25") is the value for targetBytecode to compile for a JDK 25.- See Also:
 
- 
JDK_TO_BYTECODE_VERSION_MAPJDK version to bytecode version mapping.
- 
DEFAULT_TARGET_BYTECODE
- 
ALLOWED_JDKSThe valid targetBytecode values.
- 
ASM_API_VERSIONpublic static final int ASM_API_VERSIONThe ASM API version used when loading/parsing classes and generating proxy adapter classes.- See Also:
 
- 
DEFAULT_SOURCE_ENCODINGThe default source encoding.- See Also:
 
- 
DEFAULTA convenience for getting a default configuration. Do not modify it! SeeCompilerConfiguration(Properties)for an example on how to make a suitable copy to modify. But if you're really starting from a default context, then you probably just wantnew CompilerConfiguration().
 
- 
- 
Constructor Details- 
CompilerConfigurationpublic CompilerConfiguration()Sets the compiler flags/settings to default values. The following system properties are referenced when setting the configuration:
 The following system properties are referenced when setting the configuration optimization options:Property Key Related Property Getter groovy.source.encoding(defaulting tofile.encoding)getSourceEncoding()groovy.target.bytecodegetTargetBytecode()groovy.target.directorygetTargetDirectory()groovy.parametersgetParameters()groovy.preview.featuresisPreviewFeatures()groovy.default.scriptExtensiongetDefaultScriptExtension()Property Key Related Property Getter groovy.target.indygetOptimizationOptions()groovy.parallel.parsegetOptimizationOptions()groovy.attach.groovydocgetOptimizationOptions()groovy.attach.runtime.groovydocgetOptimizationOptions()
- 
CompilerConfigurationCopy constructor. Use this if you have a mostly correct configuration for your compilation but you want to make a some changes programmatically. An important reason to prefer this approach is that your code will most likely be forward compatible with future changes to this configuration API.An example of this copy constructor at work: // In all likelihood there is already a configuration in your code's context // for you to copy, but for the sake of this example we'll use the global default. CompilerConfiguration myConfiguration = new CompilerConfiguration(CompilerConfiguration.DEFAULT); myConfiguration.setDebug(true); - Parameters:
- configuration- The configuration to copy.
 
- 
CompilerConfigurationSets the configuration flags/settings according to values from the suppliedPropertiesinstance or if not found, supplying a default value. Note that unlikeCompilerConfiguration(), the "defaults" here do not in general include checking the settings inSystem.getProperties(). If you want to set a few flags but keep Groovy's default configuration behavior then be sure to make your settings in aPropertiesobject that is backed bySystem.getProperties()(which is done using this constructor). That might be done like this:
 And you also have to contend with a possibleProperties myProperties = new Properties(System.getProperties()); myProperties.setProperty("groovy.output.debug", "true"); myConfiguration = new CompilerConfiguration(myProperties);SecurityExceptionwhen getting the system properties (SeeSystem.getProperties()). A safer approach would be to copy a defaultCompilerConfigurationand make your changes there using the setter:
 The following properties are referenced when setting the configuration:// In all likelihood there is already a configuration for you to copy, // but for the sake of this example we'll use the global default. CompilerConfiguration myConfiguration = new CompilerConfiguration(CompilerConfiguration.DEFAULT); myConfiguration.setDebug(true); Property Key Related Property Getter groovy.warningsgetWarningLevel()groovy.source.encoding(defaulting tofile.encoding)getSourceEncoding()groovy.target.directorygetTargetDirectory()groovy.target.bytecodegetTargetBytecode()groovy.parametersgetParameters()groovy.preview.featuresisPreviewFeatures()groovy.classpathgetClasspath()groovy.output.verbosegetVerbose()groovy.output.debuggetDebug()groovy.errors.tolerancegetTolerance()groovy.default.scriptExtensiongetDefaultScriptExtension()groovy.script.basegetScriptBaseClass()groovy.recompilegetRecompileGroovySource()groovy.recompile.minimumIntervalgetMinimumRecompilationInterval()groovy.disabled.global.ast.transformationsgetDisabledGlobalASTTransformations()- Parameters:
- configuration- The properties to get flag values from.
- Throws:
- ConfigurationException
 
 
- 
- 
Method Details- 
isPostJDK5Deprecated.Checks if the specified bytecode version string represents a JDK 1.5+ compatible bytecode version.- Parameters:
- bytecodeVersion- The parameter can take one of the values in- ALLOWED_JDKS.
- Returns:
- true if the bytecode version is JDK 1.5+
 
- 
isPostJDK7Deprecated.Checks if the specified bytecode version string represents a JDK 1.7+ compatible bytecode version.- Parameters:
- bytecodeVersion- The parameter can take one of the values in- ALLOWED_JDKS.
- Returns:
- true if the bytecode version is JDK 1.7+
 
- 
isPostJDK8Deprecated.Checks if the specified bytecode version string represents a JDK 1.8+ compatible bytecode version.- Parameters:
- bytecodeVersion- The parameter can take one of the values in- ALLOWED_JDKS.
- Returns:
- true if the bytecode version is JDK 1.8+
 
- 
isPostJDK9Deprecated.Checks if the specified bytecode version string represents a JDK 9+ compatible bytecode version.- Parameters:
- bytecodeVersion- The parameter can take one of the values in- ALLOWED_JDKS.
- Returns:
- true if the bytecode version is JDK 9+
 
- 
isPostJDK10Deprecated.Checks if the specified bytecode version string represents a JDK 10+ compatible bytecode version.- Parameters:
- bytecodeVersion- The parameter can take one of the values in- ALLOWED_JDKS.
- Returns:
- true if the bytecode version is JDK 10+
 
- 
isPostJDK11Checks if the specified bytecode version string represents a JDK 11+ compatible bytecode version.- Parameters:
- bytecodeVersion- The parameter can take one of the values in- ALLOWED_JDKS.
- Returns:
- true if the bytecode version is JDK 11+
 
- 
isPostJDK12Checks if the specified bytecode version string represents a JDK 12+ compatible bytecode version.- Parameters:
- bytecodeVersion- The parameter can take one of the values in- ALLOWED_JDKS.
- Returns:
- true if the bytecode version is JDK 12+
 
- 
isPostJDK13Checks if the specified bytecode version string represents a JDK 13+ compatible bytecode version.- Parameters:
- bytecodeVersion- The parameter can take one of the values in- ALLOWED_JDKS.
- Returns:
- true if the bytecode version is JDK 13+
 
- 
isPostJDK14Checks if the specified bytecode version string represents a JDK 14+ compatible bytecode version.- Parameters:
- bytecodeVersion- The parameter can take one of the values in- ALLOWED_JDKS.
- Returns:
- true if the bytecode version is JDK 14+
 
- 
isPostJDK15Checks if the specified bytecode version string represents a JDK 15+ compatible bytecode version.- Parameters:
- bytecodeVersion- The parameter can take one of the values in- ALLOWED_JDKS.
- Returns:
- true if the bytecode version is JDK 15+
 
- 
isPostJDK16Checks if the specified bytecode version string represents a JDK 16+ compatible bytecode version.- Parameters:
- bytecodeVersion- The parameter can take one of the values in- ALLOWED_JDKS.
- Returns:
- true if the bytecode version is JDK 16+
 
- 
isPostJDK17Checks if the specified bytecode version string represents a JDK 17+ compatible bytecode version.- Parameters:
- bytecodeVersion- The parameter can take one of the values in- ALLOWED_JDKS.
- Returns:
- true if the bytecode version is JDK 17+
 
- 
isPostJDK18Checks if the specified bytecode version string represents a JDK 18+ compatible bytecode version.- Parameters:
- bytecodeVersion- The parameter can take one of the values in- ALLOWED_JDKS.
- Returns:
- true if the bytecode version is JDK 18+
 
- 
configureMethod to configure a CompilerConfiguration by using Properties. For a list of available properties look atCompilerConfiguration(Properties).- Parameters:
- configuration- The properties to get flag values from.
- Throws:
- ConfigurationException
 
- 
getWarningLevelpublic int getWarningLevel()Gets the currently configured warning level. SeeWarningMessagefor level details.
- 
setWarningLevelpublic void setWarningLevel(int level) Sets the warning level. SeeWarningMessagefor level details.
- 
getSourceEncodingGets the currently configured source file encoding.
- 
setSourceEncodingSets the encoding to be used when reading source files.
- 
getOutputDeprecated.not used anymoreGets the currently configured output writer.
- 
setOutputDeprecated.not used anymore, has no effectSets the output writer.
- 
getTargetDirectoryGets the target directory for writing classes.
- 
setTargetDirectorySets the target directory.
- 
setTargetDirectorySets the target directory.
- 
getClasspath- Returns:
- the classpath
 
- 
setClasspathSets the classpath.
- 
setClasspathListsets the classpath using a list of Strings- Parameters:
- parts- list of strings containing the classpath parts
 
- 
getVerbosepublic boolean getVerbose()Returns true if verbose operation has been requested.
- 
setVerbosepublic void setVerbose(boolean verbose) Turns verbose operation on or off.
- 
getDebugpublic boolean getDebug()Returns true if debugging operation has been requested.
- 
setDebugpublic void setDebug(boolean debug) Turns debugging operation on or off.
- 
getParameterspublic boolean getParameters()Returns true if parameter metadata generation has been enabled.
- 
setParameterspublic void setParameters(boolean parameters) Turns parameter metadata generation on or off.
- 
getTolerancepublic int getTolerance()Returns the requested error tolerance.
- 
setTolerancepublic void setTolerance(int tolerance) Sets the error tolerance, which is the number of non-fatal errors (per unit) that should be tolerated before compilation is aborted.
- 
getScriptBaseClassGets the name of the base class for scripts. It must be a subclass of Script.
- 
setScriptBaseClassSets the name of the base class for scripts. It must be a subclass of Script.
- 
getPluginFactory
- 
setPluginFactory
- 
setScriptExtensions
- 
getScriptExtensions
- 
getDefaultScriptExtension
- 
setDefaultScriptExtension
- 
getRecompileGroovySourcepublic boolean getRecompileGroovySource()
- 
setRecompileGroovySourcepublic void setRecompileGroovySource(boolean recompile) 
- 
getMinimumRecompilationIntervalpublic int getMinimumRecompilationInterval()
- 
setMinimumRecompilationIntervalpublic void setMinimumRecompilationInterval(int time) 
- 
setTargetBytecodeSets the bytecode compatibility level. The parameter can take one of the values inALLOWED_JDKS.- Parameters:
- version- the bytecode compatibility level
 
- 
getTargetBytecodeRetrieves the compiler bytecode compatibility level. Defaults to the minimum officially supported bytecode version for any particular Groovy version.- Returns:
- bytecode compatibility level
 
- 
getBytecodeVersionpublic final int getBytecodeVersion()Returns the targeted bytecode (aka Java class file) version number.- Since:
- 4.0.0
 
- 
isPreviewFeaturespublic boolean isPreviewFeatures()Whether the bytecode version has preview features enabled (JEP 12)- Returns:
- preview features
 
- 
setPreviewFeaturespublic void setPreviewFeatures(boolean previewFeatures) Sets whether the bytecode version has preview features enabled (JEP 12).- Parameters:
- previewFeatures- whether to support preview features
 
- 
isLogClassgenpublic boolean isLogClassgen()Returns whether logging class generation is enabled- Returns:
- whether logging class generation is enabled
- Since:
- 4.0.0
 
- 
setLogClassgenpublic void setLogClassgen(boolean logClassgen) Sets whether logging class generation is enabled- Parameters:
- logClassgen- whether to enable logging class generation
- Since:
- 4.0.0
 
- 
getLogClassgenStackTraceMaxDepthpublic int getLogClassgenStackTraceMaxDepth()Returns stack trace max depth of logging class generation- Returns:
- stack trace max depth of logging class generation
- Since:
- 4.0.0
 
- 
setLogClassgenStackTraceMaxDepthpublic void setLogClassgenStackTraceMaxDepth(int logClassgenStackTraceMaxDepth) Sets stack trace max depth of logging class generation- Parameters:
- logClassgenStackTraceMaxDepth- stack trace max depth of logging class generation
- Since:
- 4.0.0
 
- 
getJointCompilationOptionsGets the joint compilation options for this configuration.- Returns:
- the options
 
- 
setJointCompilationOptionsSets the joint compilation options for this configuration. Using null will disable joint compilation.- Parameters:
- options- the options
 
- 
getOptimizationOptionsGets the optimization options for this configuration.- Returns:
- the options (always not null)
 
- 
setOptimizationOptionsSets the optimization options for this configuration. No entry or a true for that entry means to enable that optimization, a false means the optimization is disabled. Valid keys are "all" and "int".- Parameters:
- options- the options.
- Throws:
- IllegalArgumentException- if the options are null
 
- 
addCompilationCustomizersAdds compilation customizers to the compilation process. A compilation customizer is a class node operation which performs various operations going from adding imports to access control.- Parameters:
- customizers- the list of customizers to be added
- Returns:
- this configuration instance
 
- 
getCompilationCustomizersReturns the list of compilation customizers.- Returns:
- the customizers (always not null)
 
- 
getDisabledGlobalASTTransformationsReturns the list of disabled global AST transformation class names.- Returns:
- a list of global AST transformation fully qualified class names
 
- 
setDisabledGlobalASTTransformationsDisables the specified global AST transformations. In order to avoid class loading side effects, it is not recommended to use MyASTTransformation.class.getName() but instead directly use the class name as a string. Disabled AST transformations only apply to automatically loaded global AST transformations, that is to say transformations defined in a META-INF/services/org.codehaus.groovy.transform.ASTTransformation file. If you explicitly add a global AST transformation in your compilation process, for example using theASTTransformationCustomizeror using aCompilationUnit.IPrimaryClassNodeOperation, then nothing will prevent the transformation from being loaded.- Parameters:
- disabledGlobalASTTransformations- a set of fully qualified class names of global AST transformations which should not be loaded.
 
- 
getBytecodePostprocessor
- 
setBytecodePostprocessor
- 
isIndyEnabledpublic boolean isIndyEnabled()Checks if invoke dynamic is enabled.
- 
isGroovydocEnabledpublic boolean isGroovydocEnabled()Checks if groovydoc is enabled.
- 
isRuntimeGroovydocEnabledpublic boolean isRuntimeGroovydocEnabled()Checks if runtime groovydoc is enabled.
 
-