I can't seem to change my compiler language level ...
# getting-started
h
I can't seem to change my compiler language level in IntellIJ IDEA. I added these compiler options to the `buildSrc/build.gradle.kts`:
Copy code
plugins {
    `kotlin-dsl`
}

kotlin {
    jvmToolchain(21)
    compilerOptions {
        languageVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_1)
        apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_1)
        freeCompilerArgs.add("-Xcontext-receivers")

    }
}
All other gradle files have nothing else declared. Since 2025.1 I get errors in the editor related to context-receivers vs context-parameters. Aside from rolling back the IDE, how can I change what language level / kotlin version the editor compiler uses? When I change them in settings/build/kotlin nothing really happens, and after doing a gradle reload it's back to
2.0.21
and
2.2(latest)
. Or does is the gradle channel a better fit for this question? Edit: When I go back to 2024.3.5 it's at the same language version that I set in my gradle files.
e
org.gradle.kotlin-dsl
uses
org.gradle.embedded-kotlin
which is a fixed version of Kotlin for each Gradle release, as you can see at https://docs.gradle.org/current/userguide/compatibility.html#kotlin
KotlinVersion.KOTLIN_2_*
means K2 which should hopefully be available in Gradle 9.0, https://github.com/gradle/gradle/issues/26534
h
Thanks for the insight.
Hey sorry for reviving this, but I really wanted to use the latest intelliJ version to check out the new AI functions. But this problem prevents that since something keeps the language level of the editor at 2.2 and as such the old context receivers are marked as error.
My buildSrc/build.gradle.kts looks like this:
Copy code
plugins {
    `kotlin-dsl`
}

repositories {
    mavenCentral()
}

dependencies {
    implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.21")
}
On 2024.3.5 it works fine with the exact same gradle files, can I set a version for
kotlin-dsl
? I tried looking it up, but I can't find anything.
d
You can switch the IDE in K1 mode in
Settings -> Language & Frameworks -> Kotlin -> Enable K2 mode
Also please report an issue about problems you've faced with K2 mode: https://youtrack.jetbrains.com/newissue?project=KTIJ
h
Hey, I already created one here: https://youtrack.jetbrains.com/issue/KTIJ-34119 But there is a weird circumstance I am currently at the Home Office and here on my PC the issue isn't present. Despite having done the whole "invalidate caches, delete all .idea files, etc. " shebang at work. (both use K2) The only thing I haven't tried there was a complete re pull from the git repo. I will test it some more and then report back in the youtrack ticket. Thanks for the answer though!
👍 1
Hey I am sorry to bother with this again, but it's driving me nuts. Aside from enabling compact mode I have a very "vanilla" IntelliJ IDEA Ultimate installation. I invalidated all chaches, hit every checkbox, deleted the project, pulled it again from VCS. But I still get the context receiver error in the editor at work, but not at home. Both running 2025.1
d
What exact issues do you have?
h
The Editor red marks all context receiver uses and also no code completion for those.
d
Do you have some project which reproduces the issue and which you can share?
h
I started making one at Home when I noticed that I don't have the issue at home. I thought maybe it's something stuck at work (I have normal local admin rights on my office PC). But I can't get it to work. I just reset the IDE via Manage IDE -> Restore defaults.
Also it's only happening in the KotlinJS part of the project not the JVM one. And only in the usage of the context receiver not in the declaration. Mysterious
cannot be called in this context with an implicit receiver. Use an explicit receiver if necessary.
d
Mysterious indeed. Unfortunately there is nothing which I or my colleagues can do without a reproducer here
h
Yeah, I know, sorry 😞 I was working all day last Friday without any issue at home, same IDE Version, same git branch, etc.
The offending function in question:
d
Nope, the
KT-48215
is unrelated. It's about resolution rules, so if it would be the cause then the compilation would also fail
😞 1
h
Turns out after upgrading to 2025.1.1.1 the problem was also present on my Home PC and even downgrading back to 2025.1.1 didn't fix it there. I updated the YouTrack and appended an example project.
👍 1