How to limit a Kotlin project to a certain Java API version

I’m aware of the ability to set the generated bytecode to a specific java version via KotlinCompile:

tasks.withType<KotlinCompile>() {
    kotlinOptions.jvmTarget = "1.8"

I was wondering if there’s a possible way to lock the Java API to 1.8 as well. The above configuration will still allow me to use Java methods introduced in Java 9, 10 and so on.

This feature isn’t supported by Kotlin, however you can consider to inspect the java.version properties or use a multi-release JAR.

Thanks for your answer, it’s unfortunate to hear the feature is missing. I’ll take your suggestion of inspecting the java version for now.

You can set kotlinOptions.jdkHome to the path to a JDK 1.8, which will be used to resolve Java API at compile time.