06/29/2022, 8:04 PM
I'm mighty confused. I've got a Kotlin 1.7 project, requiring JDK 18. It doesn't compile:
e: D:\Development\Experiments\Pellet\server\src\main\kotlin\dev\pellet\server\PelletServerClient.kt: (8, 17): Unresolved reference: UnixDomainSocketAddress
IntelliJ can see the import (no red squiggly lines). In Project Structure, I've chosen SDK `openjdk-18 java version "18.0.1"`(and I've also tried the cornetto variant of JDK18). The language level is set to 17 in InteilliJ and in the
file. In IntelliJ's External Libraries view I can drill down to
and see the
class (it was introduced in Java 16). But neither IntelliJ nor Gradle can find the class to compile it! (I've even dug into the JDK source folder, and it definitely exists!). Please, any ideas?
Eventually I tried adding some really direct statements into build.gradle.kts:
kotlin {
        jvmToolchain {
And it worked. So then it dawned on me that JAVA_HOME environment variable might be wrong - and it was pointing to a JDK11 installation. So all that time I've been writing Kotlin code targeting JDK15, I've never once used a class which didn't exist and work in JDK11.
Never have I had to deal with an issue like this. I've learned my lesson.

Klitos Kyriacou

06/30/2022, 9:49 AM
I don't know why most developers define JAVA_HOME. If you don't define it, build tools will use the version of Java that's in your PATH, which is usually what you want.


06/30/2022, 10:15 AM
I'll certainly try that, thanks