gradlejavadocjava-12

Javadoc and --enable-preview


I am using Gradle 6.0.1 and JDK12 with preview features. Having the following configuration to be able to compile, run and test:

tasks.withType(JavaCompile) {
    options.compilerArgs += "--enable-preview"
}

tasks.withType(Test) {
    jvmArgs += "--enable-preview"
}

tasks.withType(JavaExec) {
    jvmArgs += '--enable-preview'
}

That works fine for all except javadoc generation that I defined as follows:

task generateJavadocs(type: Javadoc) {
    source = sourceSets.main.allJava
    options.jFlags("--enable-preview")
}

When running gradle generateJavadocs I receive compilation errors for the new switch expressions. Has anybody made it work with Javadoc?


Solution

  • I had faced the same problem with preview features of JDK 14 (and Gradle 6.3). This has worked for me:

    javadoc.options {
        addBooleanOption('-enable-preview', true)
        addStringOption('-release', '14')
    }
    

    In your case, try:

    task generateJavadocs(type: Javadoc) {
        options {
            addBooleanOption('-enable-preview', true)
            addStringOption('-release', '12')
        }
    }