https://kotlinlang.org logo
#intellij
Title
# intellij
m

mbonnin

03/01/2023, 2:40 PM
Can intelliJ detect the JVM toolchain/target version of some file based on Gradle configuration?
Thread.id
is deprecated in Java 19 (which is my JAVA_HOME). But I'm compiling with
jvmTarget = "1.8"
so it shouldn't be a warning?
Changing Project settings fixes it but it feels wrong to have to duplicate this?
Also interestingly, it seems to be bound to the SDK version while I would expect it to be bound to the Language Level instead
r

Riccardo Lippolis

03/01/2023, 4:00 PM
If I remember correctly, this can be controlled by the Java toolchain version in the Gradle build file (https://docs.gradle.org/current/userguide/toolchains.html), I don't think the Kotlin compiler plugin will automatically take over the Java toolchain JVM version, but you could at least use a common property for it, something like (assuming a
build.gradle.kts
):
Copy code
val jvmVersion = 19

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

tasks.compileKotlin {
    kotlinOptions {
        jvmTarget = "$jvmVersion"
    }
}
m

mbonnin

03/01/2023, 4:01 PM
That part works. My issue is with IntelliJ is not picking this up
i.e. it shows false positive warnings
r

Riccardo Lippolis

03/01/2023, 4:17 PM
ah okay, then I misunderstood!
s

spand

03/02/2023, 3:43 PM
I think it on the way. Scroll down to
Java SDK detected from the Gradle toolchain
https://blog.jetbrains.com/idea/2023/02/intellij-idea-2023-1-eap-6
👀 1
m

mbonnin

03/02/2023, 3:44 PM
Oohhooh very nice
I'm already on 2023.1 though 🤔 . Let me try again
So that doesn't work out of the box (I'm using toolchains with Java17)
Trying to clean my .idea folder
26 Views