This message was deleted.
# community-support
s
This message was deleted.
e
Copy code
plugins {
    `java-library`
    kotlin("jvm")
}

val java11 by sourceSets.creating {
    java.source(sourceSets.main.get().java)
    kotlin.source(sourceSets.main.get().kotlin)
    resources.source(sourceSets.main.get().resources)
}

java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(17))
    }

    registerFeature("java11") {
        usingSourceSet(java11)
    }
}

tasks.named<JavaCompile>("compileJava11Java") {
    javaCompiler.set(javaToolchains.compilerFor {
        languageVersion.set(JavaLanguageVersion.of(11))
    })
}

tasks.named<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>("compileJava11Kotlin") {
    kotlinJavaToolchain.toolchain.use(javaToolchains.launcherFor {
        languageVersion.set(JavaLanguageVersion.of(11))
    })
}
v
May I ask why? What do you hope to gain from that?
👍 2
e
You can build with Java 17 and still target Java 11 so the consumers aren't affected.
e
… sorta. it's hard to avoid issues like the
Buffer.flip
overloads in Java versions past 11 unless you're actually using JDK 11 (or equivalent with
--release
)
but yeah, I'm not sure what the point is… if you need to produce 11-compatible output, just stick with 11
https://www.morling.dev/blog/bytebuffer-and-the-dreaded-nosuchmethoderror/ oh that particular one was actually introduced at 9, so I misremembered the version
v
The breaking change in
ByteBuffer
methods was in 13
e
oh, did I misinterpret the article or is it wrong? in that case you'd still be subject to it if you want to use 17 but provide artifacts for 11
v
Using
--release
should actually mitigate the problem. But the question is still, why one should want to do that.
Ah, ok, there was a breaking change in Java 9 already for
position
. I wasn't aware of that. In Java 13 there were more such breaking changes like
flip
and some more.
That's exactly why there is
-release
so you can compile against the target API version. This was there before JVM toolchains feature and could be used. But nowadays I'd prefer to just set the proper toolchain version.