How can I set the compileOptions for my Gradle Java plugin?

You cannot overwrite all of the options (since 'options' property is read-only), but you can set them one by one. For example:

compileJava {
    //enable compilation in a separate daemon process
    options.fork = true

    //enable incremental compilation
    options.incremental = true
}

Check out the docs: https://gradle.org/docs/current/dsl/org.gradle.api.tasks.compile.JavaCompile.html and https://gradle.org/docs/current/dsl/org.gradle.api.tasks.compile.CompileOptions.html


If you're using kotlin, then:

build.gradle.kts

tasks.withType<JavaCompile>(){
    options.compilerArgs.addAll(listOf("-nowarn", "-Xlint:none"))
}

tasks.withType(JavaCompile) {
    configure(options) {
        options.compilerArgs << '-Xlint:deprecation' << '-Xlint:unchecked' // examples
    }
}

Source: http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.compile.CompileOptions.html


Please try:

apply plugin: 'java'

compileJava {
    options.compilerArgs << '-parameters' 
}

Tags:

Java

Gradle