Hi, I’m using Kotlin to publish a Java lib (<https...
# random
g
Hi, I’m using Kotlin to publish a Java lib (https://infinitic.io). Currently I’m targeting Java 11, but some users request to use Java 17. I’m wondering what are the best practices here? Eg. Should I publish the lib under different Java version?
h
What’s the problem with targeting Java 11 and consume it with Java 17, JavaEE? If so, I would either try to split the lib into core, java11 and java17, either with 3 gradle modules or if you prefer Gradle variants, one module with 2 variants.
g
There is no problem for targeting 11 and consume with 17, but some users think that targeting 17 will improve performance.
h
I don’t think the target level has a real impact. But you can also use eg Java 21 to compile your code but target 11. This allows you to use some improvements of 21 compiler but you only need one code base.
1
g
I use Kotlin, can I specify Java compiler version? It seems an obvious question, but I’ve never looked at those subjects in details
h
Yes:
Copy code
kotlin {
    jvmToolchain(21)
    compilerOptions {
        jvmTarget.set(JvmTarget.JVM_11)
    }
}
Copy code
java {
    targetCompatibility = JavaVersion.VERSION_11
}
👍 1
gratitude thank you 1
e
The bytecode will be the same anyway. The JVM will consume it with better optimization in the latest releases but that's it. I don't recall any bytecode enhancements from the Kotlin compiler past Java 11.