Package org.gradle.api.tasks.compile

# Class CompileOptions

java.lang.Object
org.gradle.api.tasks.compile.CompileOptions

All Implemented Interfaces:
  `Serializable`

public abstract class CompileOptions extends Object implements Serializable
Main options for Java compilation.

See Also:
  - Serialized Form

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CompileOptions(ObjectFactory objectFactory)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `debugOptions(Action<? super DebugOptions> action)`
  Execute the given action against `getDebugOptions()`.
  `void`
  `forkOptions(Action<? super ForkOptions> action)`
  Execute the given action against `getForkOptions()`.
  `Provider<List<String>>`
  `getAllCompilerArgs()`
  Returns all compiler arguments, added to the `getCompilerArgs()` or the `getCompilerArgumentProviders()` property.
  `abstract ConfigurableFileCollection`
  `getAnnotationProcessorPath()`
  Returns the classpath to use to load annotation processors.
  `abstract ConfigurableFileCollection`
  `getBootstrapClasspath()`
  Returns the bootstrap classpath to be used for the compiler process.
  `abstract ListProperty<String>`
  `getCompilerArgs()`
  Returns any additional arguments to be passed to the compiler.
  `abstract ListProperty<CommandLineArgumentProvider>`
  `getCompilerArgumentProviders()`
  Compiler argument providers.
  `abstract Property<Boolean>`
  `getDebug()`
  Tells whether to include debugging information in the generated class files.
  `abstract DebugOptions`
  `getDebugOptions()`
  Returns options for generating debugging information.
  `abstract Property<Boolean>`
  `getDeprecation()`
  Tells whether to log details of usage of deprecated members or classes.
  `abstract Property<String>`
  `getEncoding()`
  Returns the character encoding to be used when reading source files.
  `abstract Property<String>`
  `getExtensionDirs()`
  Returns the extension dirs to be used for the compiler process.
  `abstract Property<Boolean>`
  `getFailOnError()`
  Sets whether to fail the build when compilation fails.
  `abstract Property<Boolean>`
  `getFork()`
  Tells whether to run the compiler in its own process.
  `abstract ForkOptions`
  `getForkOptions()`
  Returns options for running the compiler in a child process.
  `abstract DirectoryProperty`
  `getGeneratedSourceOutputDirectory()`
  Returns the directory to place source files generated by annotation processors.
  `abstract 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.
  `abstract Property<Boolean>`
  `getIncremental()`
  informs whether to use incremental compilation feature.
  `abstract Property<Boolean>`
  `getIncrementalAfterFailure()`
  Used to enable or disable incremental compilation after a failure.
  `Property<Boolean>`
  `getIsDebug()`
  Sets whether to include debugging information in the generated class files.
  `Property<Boolean>`
  `getIsDeprecation()`
  Sets whether to log details of usage of deprecated members or classes.
  `Property<Boolean>`
  `getIsFailOnError()`
  `Property<Boolean>`
  `getIsFork()`
  Sets whether to run the compiler in its own process.
  `Property<Boolean>`
  `getIsIncremental()`
  `Property<Boolean>`
  `getIsListFiles()`
  `Property<Boolean>`
  `getIsVerbose()`
  `Property<Boolean>`
  `getIsWarnings()`
  Sets whether to log warning messages.
  `abstract Property<String>`
  `getJavaModuleMainClass()`
  Set the main class of the Java module, if the module is supposed to be executable.
  `abstract Property<String>`
  `getJavaModuleVersion()`
  Set the version of the Java module.
  `abstract Property<Boolean>`
  `getListFiles()`
  Tells whether to log the files to be compiled.
  `abstract Property<Integer>`
  `getRelease()`
  Configures the Java language version for this compile task (`--release` compiler flag).
  `abstract ConfigurableFileCollection`
  `getSourcepath()`
  The source path to use for the compilation.
  `abstract Property<Boolean>`
  `getVerbose()`
  Tells whether to produce verbose output.
  `abstract Property<Boolean>`
  `getWarnings()`
  Tells whether to log warning messages.
  `void`
  `setAnnotationProcessorPath(@Nullable FileCollection annotationProcessorPath)`
  Set the classpath to use to load annotation processors.
  `void`
  `setBootstrapClasspath(@Nullable FileCollection bootstrapClasspath)`
  Sets the bootstrap classpath to be used for the compiler process.
  `void`
  `setCompilerArgs(List<String> compilerArgs)`
  Sets any additional arguments to be passed to the compiler.
  `void`
  `setDebug(boolean debug)`
  Sets whether to include debugging information in the generated class files.
  `void`
  `setDeprecation(boolean deprecation)`
  Sets whether to log details of usage of deprecated members or classes.
  `void`
  `setEncoding(@Nullable String encoding)`
  Sets the character encoding to be used when reading source files.
  `void`
  `setExtensionDirs(@Nullable String extensionDirs)`
  Sets the extension dirs to be used for the compiler process.
  `void`
  `setFailOnError(boolean failOnError)`
  Sets whether to fail the build when compilation fails.
  `void`
  `setFork(boolean fork)`
  Sets whether to run the compiler in its own process.
  `CompileOptions`
  `setIncremental(boolean incremental)`
  Configure the java compilation to be incremental (e.g.
  `void`
  `setListFiles(boolean listFiles)`
  Sets whether to log the files to be compiled.
  `void`
  `setSourcepath(@Nullable FileCollection sourcepath)`
  Sets the source path to use for the compilation.
  `void`
  `setVerbose(boolean verbose)`
  Sets whether to produce verbose output.
  `void`
  `setWarnings(boolean warnings)`
  Sets whether to log warning messages.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### CompileOptions

    @Inject public CompileOptions(ObjectFactory objectFactory)

- ## Method Details

  - ### getFailOnError

    @Input public abstract Property<Boolean> getFailOnError()
    Sets whether to fail the build when compilation fails. Defaults to `true`.

  - ### getIsFailOnError

    @ReplacedBy("failOnError") public Property<Boolean> getIsFailOnError()

  - ### setFailOnError

    public void setFailOnError(boolean failOnError)
    Sets whether to fail the build when compilation fails. Defaults to `true`.

  - ### getVerbose

    @Console public abstract Property<Boolean> getVerbose()
    Tells whether to produce verbose output. Defaults to `false`.

  - ### getIsVerbose

    @ReplacedBy("verbose") public Property<Boolean> getIsVerbose()

  - ### setVerbose

    public void setVerbose(boolean verbose)
    Sets whether to produce verbose output. Defaults to `false`.

  - ### getListFiles

    @Console public abstract Property<Boolean> getListFiles()
    Tells whether to log the files to be compiled. Defaults to `false`.

  - ### getIsListFiles

    @ReplacedBy("listFiles") public Property<Boolean> getIsListFiles()

  - ### setListFiles

    public void setListFiles(boolean listFiles)
    Sets whether to log the files to be compiled. Defaults to `false`.

  - ### getDeprecation

    @Console public abstract Property<Boolean> getDeprecation()
    Tells whether to log details of usage of deprecated members or classes. Defaults to `false`.

  - ### getIsDeprecation

    @ReplacedBy("deprecation") public Property<Boolean> getIsDeprecation()
    Sets whether to log details of usage of deprecated members or classes. Defaults to `false`.

  - ### setDeprecation

    public void setDeprecation(boolean deprecation)
    Sets whether to log details of usage of deprecated members or classes. Defaults to `false`.

  - ### getWarnings

    @Console public abstract Property<Boolean> getWarnings()
    Tells whether to log warning messages. The default is `true`.

  - ### getIsWarnings

    @ReplacedBy("warnings") public Property<Boolean> getIsWarnings()
    Sets whether to log warning messages. The default is `true`.

  - ### setWarnings

    public void setWarnings(boolean warnings)
    Sets whether to log warning messages. The default is `true`.

  - ### getEncoding

    @Optional @Input public abstract Property<String> getEncoding()
    Returns the character encoding to be used when reading source files. Defaults to `null`, 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 to `null`, in which case the platform default encoding will be used.

  - ### getDebug

    @Input public abstract Property<Boolean> getDebug()
    Tells whether to include debugging information in the generated class files. Defaults to `true`. See `DebugOptions.getDebugLevel()` for which debugging information will be generated.

  - ### getIsDebug

    @ReplacedBy("debug") public Property<Boolean> getIsDebug()
    Sets whether to include debugging information in the generated class files. Defaults to `true`. See `DebugOptions.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 to `true`. See `DebugOptions.getDebugLevel()` for which debugging information will be generated.

  - ### getDebugOptions

    public abstract DebugOptions getDebugOptions()
    Returns options for generating debugging information.

  - ### debugOptions

    public void debugOptions(Action<? super DebugOptions> action)
    Execute the given action against `getDebugOptions()`.
    Since:
      8.11

  - ### getFork

    @Input public abstract Property<Boolean> getFork()
    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 to `false`.

  - ### getIsFork

    @ReplacedBy("fork") public Property<Boolean> getIsFork()
    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 to `false`.

  - ### 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 to `false`.

  - ### getForkOptions

    public abstract ForkOptions getForkOptions()
    Returns options for running the compiler in a child process.

  - ### forkOptions

    public void forkOptions(Action<? super ForkOptions> action)
    Execute the given action against `getForkOptions()`.
    Since:
      8.11

  - ### getBootstrapClasspath

    @Optional @CompileClasspath public abstract ConfigurableFileCollection getBootstrapClasspath()
    Returns the bootstrap classpath to be used for the compiler process. Defaults to empty.
    Since:
      4.3

  - ### setBootstrapClasspath

    public void setBootstrapClasspath(@Nullable FileCollection bootstrapClasspath)
    Sets the bootstrap classpath to be used for the compiler process. Defaults to `null`.
    Since:
      4.3

  - ### getExtensionDirs

    @Optional @Input public abstract Property<String> getExtensionDirs()
    Returns the extension dirs to be used for the compiler process. Defaults to `null`.

  - ### setExtensionDirs

    public void setExtensionDirs(@Nullable String extensionDirs)
    Sets the extension dirs to be used for the compiler process. Defaults to `null`.

  - ### getCompilerArgs

    @Input public abstract ListProperty<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 `--enable-preview` option that was added in newer Java versions:

        compilerArgs.add("--enable-preview")

    Note that if `--release` is added then `-target` and `-source` are ignored.

  - ### setCompilerArgs

    public void setCompilerArgs(List<String> compilerArgs)
    Sets any additional arguments to be passed to the compiler. Defaults to the empty list.

  - ### getAllCompilerArgs

    @Internal public Provider<List<String>> getAllCompilerArgs()
    Returns all compiler arguments, added to the `getCompilerArgs()` or the `getCompilerArgumentProviders()` property.
    Since:
      4.5

  - ### getCompilerArgumentProviders

    public abstract ListProperty<CommandLineArgumentProvider> getCompilerArgumentProviders()
    Compiler argument providers.
    Since:
      4.5

  - ### getIncremental

    @Internal public abstract Property<Boolean> getIncremental()
    informs whether to use incremental compilation feature.

  - ### getIsIncremental

    @ReplacedBy("incremental") public Property<Boolean> getIsIncremental()

  - ### 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).

  - ### getIncrementalAfterFailure

    @Input @Optional public abstract Property<Boolean> getIncrementalAfterFailure()
    Used to enable or disable incremental compilation after a failure.

    By default, incremental compilation after a failure is enabled for Java and Groovy. It has no effect for Scala. It has no effect if incremental compilation is not enabled.

    When the Java command line compiler is used, i.e. when a custom java home is passed to forkOptions.javaHome or javac is passed to forkOptions.executable, this optimization is automatically disabled, since the compiler is not invoked via the compiler API.

    Since:
      7.6

  - ### getSourcepath

    @Optional @IgnoreEmptyDirectories @PathSensitive(RELATIVE) @InputFiles public abstract ConfigurableFileCollection 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 `-sourcepath` option for `javac`, 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

  - ### setSourcepath

    public void setSourcepath(@Nullable FileCollection sourcepath)
    Sets the source path to use for the compilation.
    Parameters:
      `sourcepath` - the source path

  - ### getAnnotationProcessorPath

    @Optional @Classpath public abstract ConfigurableFileCollection 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 `null` if 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, or `null` to disable annotation processing.
    Since:
      3.4

  - ### getRelease

    @Input @Optional public abstract Property<Integer> getRelease()
    Configures the Java language version for this compile task (`--release` compiler flag).

    If set, it will take precedences over the `AbstractCompile.getSourceCompatibility()` and `AbstractCompile.getTargetCompatibility()` settings.

    This option is only taken into account by the `JavaCompile` task.

    Since:
      6.6

  - ### getJavaModuleVersion

    @Optional @Input public abstract Property<String> getJavaModuleVersion()
    Set the version of the Java module.
    Since:
      6.4

  - ### getJavaModuleMainClass

    @Optional @Input public abstract Property<String> getJavaModuleMainClass()
    Set the main class of the Java module, if the module is supposed to be executable.
    Since:
      6.4

  - ### getGeneratedSourceOutputDirectory

    @Optional @OutputDirectory public abstract DirectoryProperty getGeneratedSourceOutputDirectory()
    Returns the directory to place source files generated by annotation processors.
    Since:
      6.3

  - ### getHeaderOutputDirectory

    @Optional @OutputDirectory public abstract 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