Class CompileOptions

  • All Implemented Interfaces:
    java.io.Serializable

    public abstract class CompileOptions
    extends AbstractOptions
    Main options for Java compilation.
    See Also:
    Serialized Form
    • Constructor Detail

      • CompileOptions

        @Inject
        public CompileOptions​(ObjectFactory objectFactory)
    • Method Detail

      • isFailOnError

        @Input
        public boolean isFailOnError()
        Tells whether to fail the build when compilation fails. Defaults to true.
      • setFailOnError

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

        @Console
        public boolean isVerbose()
        Tells whether to produce verbose output. Defaults to false.
      • setVerbose

        public void setVerbose​(boolean verbose)
        Sets whether to produce verbose output. Defaults to false.
      • isListFiles

        @Console
        public boolean isListFiles()
        Tells whether to log the files to be compiled. Defaults to false.
      • setListFiles

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

        @Console
        public boolean isDeprecation()
        Tells 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.
      • isWarnings

        @Console
        public boolean isWarnings()
        Tells 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

        @Nullable
        @Optional
        @Input
        public java.lang.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
                                java.lang.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.
      • isDebug

        @Input
        public boolean isDebug()
        Tells 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 DebugOptions getDebugOptions()
        Returns options for generating debugging information.
      • setDebugOptions

        @Deprecated
        public void setDebugOptions​(DebugOptions debugOptions)
        Deprecated.
        Setting a new instance of this property is unnecessary. This method will be removed in Gradle 9.0. Use debugOptions(Action) instead.
        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 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 ForkOptions getForkOptions()
        Returns options for running the compiler in a child process.
      • setForkOptions

        @Deprecated
        public void setForkOptions​(ForkOptions forkOptions)
        Deprecated.
        Setting a new instance of this property is unnecessary. This method will be removed in Gradle 9.0. Use forkOptions(Action) instead.
        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 to null.
        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

        @Nullable
        @Optional
        @Input
        public java.lang.String getExtensionDirs()
        Returns the extension dirs to be used for the compiler process. Defaults to null.
      • setExtensionDirs

        public void setExtensionDirs​(@Nullable
                                     java.lang.String extensionDirs)
        Sets the extension dirs to be used for the compiler process. Defaults to null.
      • getCompilerArgs

        @Input
        public java.util.List<java.lang.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.
      • getCompilerArgumentProviders

        public java.util.List<CommandLineArgumentProvider> getCompilerArgumentProviders()
        Compiler argument providers.
        Since:
        4.5
      • setCompilerArgs

        public void setCompilerArgs​(java.util.List<java.lang.String> compilerArgs)
        Sets any additional arguments to be passed to the compiler. Defaults to the empty list.
      • fork

        @Deprecated
        public CompileOptions fork​(java.util.Map<java.lang.String,​java.lang.Object> forkArgs)
        Deprecated.
        This method will be removed in Gradle 9.0
        Convenience method to set ForkOptions with named parameter syntax. Calling this method will set fork to true.
      • debug

        @Deprecated
        public CompileOptions debug​(java.util.Map<java.lang.String,​java.lang.Object> debugArgs)
        Deprecated.
        This method will be removed in Gradle 9.0
        Convenience method to set DebugOptions with named parameter syntax. Calling this method will set debug to true.
      • 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
        @Incubating
        public Property<java.lang.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
        @Nullable
        @IgnoreEmptyDirectories
        @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 -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
        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 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
      • getJavaModuleVersion

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

        @Optional
        @Input
        public Property<java.lang.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 DirectoryProperty getGeneratedSourceOutputDirectory()
        Returns the directory to place source files generated by annotation processors.
        Since:
        6.3
      • getAnnotationProcessorGeneratedSourcesDirectory

        @Nullable
        @Deprecated
        @ReplacedBy("generatedSourceOutputDirectory")
        public java.io.File getAnnotationProcessorGeneratedSourcesDirectory()
        Deprecated.
        Use getGeneratedSourceOutputDirectory() instead. This method will be removed in Gradle 9.0.
        Returns the directory to place source files generated by annotation processors.
        Since:
        4.3
      • setAnnotationProcessorGeneratedSourcesDirectory

        @Deprecated
        public void setAnnotationProcessorGeneratedSourcesDirectory​(@Nullable
                                                                    java.io.File file)
        Deprecated.
        Use getGeneratedSourceOutputDirectory().set() instead. This method will be removed in Gradle 9.0.
        Sets the directory to place source files generated by annotation processors.
        Since:
        4.3
      • setAnnotationProcessorGeneratedSourcesDirectory

        @Deprecated
        public void setAnnotationProcessorGeneratedSourcesDirectory​(Provider<java.io.File> file)
        Deprecated.
        Use getGeneratedSourceOutputDirectory().set() instead. This method will be removed in Gradle 9.0.
        Sets the directory to place source files generated by annotation processors.
        Since:
        4.3
      • getHeaderOutputDirectory

        @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