Skip to content

Javac's --release flag is not respected when setting Java compatibility #113

@TheMrMilchmann

Description

@TheMrMilchmann

The fix for #95 in 1.6.13 actually broke the compilation in my case. Here is what I typically do:

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(22)
    }
}

withType<JavaCompile>().configureEach {
    options.release = 8
}

This configuration uses the latest toolchain to compile for a specific Java version. However, as of the changes in 1.6.13, this is no longer supported. The culprit seems to be that the compatibility versions are set to the toolchain versions regardless of whether options.release is specified and then take precedence.

For example, this issue surfaces when writing a plugin in Kotlin:

kotlin {
    compilerOptions {
        jvmTarget = JvmTarget.JVM_1_8
    }
}

Running a build then fails even if options.release is set with:

Inconsistent JVM-target compatibility detected for tasks 'compileJava' (22) and 'compileKotlin' (1.8).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions