Package org.gradle.api.tasks.compile
Class CompileOptions
- java.lang.Object
-
- org.gradle.api.tasks.compile.AbstractOptions
-
- org.gradle.api.tasks.compile.CompileOptions
-
- All Implemented Interfaces:
Serializable
public class CompileOptions extends AbstractOptions
Main options for Java compilation.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description CompileOptions(ProjectLayout projectLayout, ObjectFactory objectFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CompileOptionsdebug(Map<String,Object> debugArgs)Convenience method to setDebugOptionswith named parameter syntax.protected booleanexcludeFromAntProperties(String fieldName)CompileOptionsfork(Map<String,Object> forkArgs)Convenience method to setForkOptionswith named parameter syntax.List<String>getAllCompilerArgs()Returns all compiler arguments, added to thegetCompilerArgs()or thegetCompilerArgumentProviders()property.FilegetAnnotationProcessorGeneratedSourcesDirectory()Returns the directory to place source files generated by annotation processors.FileCollectiongetAnnotationProcessorPath()Returns the classpath to use to load annotation processors.protected StringgetAntPropertyName(String fieldName)protected ObjectgetAntPropertyValue(String fieldName, Object value)FileCollectiongetBootstrapClasspath()Returns the bootstrap classpath to be used for the compiler process.List<String>getCompilerArgs()Returns any additional arguments to be passed to the compiler.List<CommandLineArgumentProvider>getCompilerArgumentProviders()Compiler argument providers.DebugOptionsgetDebugOptions()Returns options for generating debugging information.StringgetEncoding()Returns the character encoding to be used when reading source files.StringgetExtensionDirs()Returns the extension dirs to be used for the compiler process.ForkOptionsgetForkOptions()Returns options for running the compiler in a child process.DirectoryPropertygetHeaderOutputDirectory()If this option is set to a non-null directory, it will be passed to the Java compiler's `-h` option, prompting it to generate native headers to that directory.FileCollectiongetSourcepath()The source path to use for the compilation.booleanisDebug()Tells whether to include debugging information in the generated class files.booleanisDeprecation()Tells whether to log details of usage of deprecated members or classes.booleanisFailOnError()Tells whether to fail the build when compilation fails.booleanisFork()Tells whether to run the compiler in its own process.booleanisIncremental()informs whether to use incremental compilation feature.booleanisListFiles()Tells whether to log the files to be compiled.booleanisVerbose()Tells whether to produce verbose output.booleanisWarnings()Tells whether to log warning messages.Map<String,Object>optionMap()Internal method.voidsetAnnotationProcessorGeneratedSourcesDirectory(File file)Sets the directory to place source files generated by annotation processors.voidsetAnnotationProcessorGeneratedSourcesDirectory(Provider<File> file)Sets the directory to place source files generated by annotation processors.voidsetAnnotationProcessorPath(FileCollection annotationProcessorPath)Set the classpath to use to load annotation processors.voidsetBootstrapClasspath(FileCollection bootstrapClasspath)Sets the bootstrap classpath to be used for the compiler process.voidsetCompilerArgs(List<String> compilerArgs)Sets any additional arguments to be passed to the compiler.voidsetDebug(boolean debug)Sets whether to include debugging information in the generated class files.voidsetDebugOptions(DebugOptions debugOptions)Sets options for generating debugging information.voidsetDeprecation(boolean deprecation)Sets whether to log details of usage of deprecated members or classes.voidsetEncoding(String encoding)Sets the character encoding to be used when reading source files.voidsetExtensionDirs(String extensionDirs)Sets the extension dirs to be used for the compiler process.voidsetFailOnError(boolean failOnError)Sets whether to fail the build when compilation fails.voidsetFork(boolean fork)Sets whether to run the compiler in its own process.voidsetForkOptions(ForkOptions forkOptions)Sets options for running the compiler in a child process.CompileOptionssetIncremental(boolean incremental)Configure the java compilation to be incremental (e.g.voidsetListFiles(boolean listFiles)Sets whether to log the files to be compiled.voidsetSourcepath(FileCollection sourcepath)Sets the source path to use for the compilation.voidsetVerbose(boolean verbose)Sets whether to produce verbose output.voidsetWarnings(boolean warnings)Sets whether to log warning messages.-
Methods inherited from class org.gradle.api.tasks.compile.AbstractOptions
define
-
-
-
-
Constructor Detail
-
CompileOptions
@Inject public CompileOptions(ProjectLayout projectLayout, ObjectFactory objectFactory)
-
-
Method Detail
-
isFailOnError
@Input public boolean isFailOnError()
Tells whether to fail the build when compilation fails. Defaults totrue.
-
setFailOnError
public void setFailOnError(boolean failOnError)
Sets whether to fail the build when compilation fails. Defaults totrue.
-
isVerbose
@Console public boolean isVerbose()
Tells whether to produce verbose output. Defaults tofalse.
-
setVerbose
public void setVerbose(boolean verbose)
Sets whether to produce verbose output. Defaults tofalse.
-
isListFiles
@Console public boolean isListFiles()
Tells whether to log the files to be compiled. Defaults tofalse.
-
setListFiles
public void setListFiles(boolean listFiles)
Sets whether to log the files to be compiled. Defaults tofalse.
-
isDeprecation
@Console public boolean isDeprecation()
Tells whether to log details of usage of deprecated members or classes. Defaults tofalse.
-
setDeprecation
public void setDeprecation(boolean deprecation)
Sets whether to log details of usage of deprecated members or classes. Defaults tofalse.
-
isWarnings
@Console public boolean isWarnings()
Tells whether to log warning messages. The default istrue.
-
setWarnings
public void setWarnings(boolean warnings)
Sets whether to log warning messages. The default istrue.
-
getEncoding
@Nullable @Optional @Input public String getEncoding()
Returns the character encoding to be used when reading source files. Defaults tonull, in which case the platform default encoding will be used.
-
setEncoding
public void setEncoding(@Nullable String encoding)
Sets the character encoding to be used when reading source files. Defaults tonull, in which case the platform default encoding will be used.
-
isDebug
@Input public boolean isDebug()
Tells whether to include debugging information in the generated class files. Defaults totrue. SeeDebugOptions.getDebugLevel()for which debugging information will be generated.
-
setDebug
public void setDebug(boolean debug)
Sets whether to include debugging information in the generated class files. Defaults totrue. SeeDebugOptions.getDebugLevel()for which debugging information will be generated.
-
getDebugOptions
public DebugOptions getDebugOptions()
Returns options for generating debugging information.
-
setDebugOptions
public void setDebugOptions(DebugOptions debugOptions)
Sets options for generating debugging information.
-
isFork
@Input public boolean isFork()
Tells whether to run the compiler in its own process. Note that this does not necessarily mean that a new process will be created for each compile task. Defaults tofalse.
-
setFork
public void setFork(boolean fork)
Sets whether to run the compiler in its own process. Note that this does not necessarily mean that a new process will be created for each compile task. Defaults tofalse.
-
getForkOptions
public ForkOptions getForkOptions()
Returns options for running the compiler in a child process.
-
setForkOptions
public void setForkOptions(ForkOptions forkOptions)
Sets options for running the compiler in a child process.
-
getBootstrapClasspath
@Nullable @Optional @CompileClasspath public FileCollection getBootstrapClasspath()
Returns the bootstrap classpath to be used for the compiler process. Defaults tonull.- Since:
- 4.3
-
setBootstrapClasspath
public void setBootstrapClasspath(@Nullable FileCollection bootstrapClasspath)
Sets the bootstrap classpath to be used for the compiler process. Defaults tonull.- Since:
- 4.3
-
getExtensionDirs
@Nullable @Optional @Input public String getExtensionDirs()
Returns the extension dirs to be used for the compiler process. Defaults tonull.
-
setExtensionDirs
public void setExtensionDirs(@Nullable String extensionDirs)
Sets the extension dirs to be used for the compiler process. Defaults tonull.
-
getCompilerArgs
@Input public List<String> getCompilerArgs()
Returns any additional arguments to be passed to the compiler. Defaults to the empty list. Compiler arguments not supported by the DSL can be added here. For example, it is possible to pass the--releaseoption of JDK 9:
Note that ifcompilerArgs.addAll(['--release', '7'])--releaseis added then-targetand-sourceare ignored.
-
getAllCompilerArgs
@Incubating @Internal public List<String> getAllCompilerArgs()
Returns all compiler arguments, added to thegetCompilerArgs()or thegetCompilerArgumentProviders()property.- Since:
- 4.5
-
getCompilerArgumentProviders
@Incubating public List<CommandLineArgumentProvider> getCompilerArgumentProviders()
Compiler argument providers.- Since:
- 4.5
-
setCompilerArgs
public void setCompilerArgs(List<String> compilerArgs)
Sets any additional arguments to be passed to the compiler. Defaults to the empty list.
-
fork
public CompileOptions fork(Map<String,Object> forkArgs)
Convenience method to setForkOptionswith named parameter syntax. Calling this method will setforktotrue.
-
debug
public CompileOptions debug(Map<String,Object> debugArgs)
Convenience method to setDebugOptionswith named parameter syntax. Calling this method will setdebugtotrue.
-
setIncremental
public CompileOptions setIncremental(boolean incremental)
Configure the java compilation to be incremental (e.g. compiles only those java classes that were changed or that are dependencies to the changed classes).
-
optionMap
public Map<String,Object> optionMap()
Internal method.- Overrides:
optionMapin classAbstractOptions
-
excludeFromAntProperties
protected boolean excludeFromAntProperties(String fieldName)
- Overrides:
excludeFromAntPropertiesin classAbstractOptions
-
getAntPropertyName
protected String getAntPropertyName(String fieldName)
- Overrides:
getAntPropertyNamein classAbstractOptions
-
getAntPropertyValue
protected Object getAntPropertyValue(String fieldName, Object value)
- Overrides:
getAntPropertyValuein classAbstractOptions
-
isIncremental
@Internal public boolean isIncremental()
informs whether to use incremental compilation feature. SeesetIncremental(boolean)
-
getSourcepath
@Optional @Nullable @PathSensitive(RELATIVE) @InputFiles public FileCollection getSourcepath()
The source path to use for the compilation.The source path indicates the location of source files that may be compiled if necessary. It is effectively a complement to the class path, where the classes to be compiled against are in source form. It does not indicate the actual primary source being compiled.
The source path feature of the Java compiler is rarely needed for modern builds that use dependency management.
The default value for the source path is
null, which indicates an empty source path. Note that this is different to the default value for the-sourcepathoption forjavac, which is to use the value specified by-classpath. If you wish to use any source path, it must be explicitly set.- Returns:
- the source path
- See Also:
setSourcepath(FileCollection)
-
setSourcepath
public void setSourcepath(@Nullable FileCollection sourcepath)
Sets the source path to use for the compilation.- Parameters:
sourcepath- the source path
-
getAnnotationProcessorPath
@Nullable @Optional @Classpath public FileCollection getAnnotationProcessorPath()
Returns the classpath to use to load annotation processors. This path is also used for annotation processor discovery.- Returns:
- The annotation processor path, or
nullif annotation processing is disabled. - Since:
- 3.4
-
setAnnotationProcessorPath
public void setAnnotationProcessorPath(@Nullable FileCollection annotationProcessorPath)
Set the classpath to use to load annotation processors. This path is also used for annotation processor discovery.- Parameters:
annotationProcessorPath- The annotation processor path, ornullto disable annotation processing.- Since:
- 3.4
-
getAnnotationProcessorGeneratedSourcesDirectory
@Incubating @Nullable @Optional @OutputDirectory public File getAnnotationProcessorGeneratedSourcesDirectory()
Returns the directory to place source files generated by annotation processors.- Since:
- 4.3
-
setAnnotationProcessorGeneratedSourcesDirectory
@Incubating public void setAnnotationProcessorGeneratedSourcesDirectory(@Nullable File file)
Sets the directory to place source files generated by annotation processors.- Since:
- 4.3
-
setAnnotationProcessorGeneratedSourcesDirectory
@Incubating public void setAnnotationProcessorGeneratedSourcesDirectory(Provider<File> file)
Sets the directory to place source files generated by annotation processors.- Since:
- 4.3
-
getHeaderOutputDirectory
@Incubating @Optional @OutputDirectory public DirectoryProperty getHeaderOutputDirectory()
If this option is set to a non-null directory, it will be passed to the Java compiler's `-h` option, prompting it to generate native headers to that directory.- Since:
- 4.10
-
-