While migrating to Kotlin 2 I get the error in a c...
# getting-started
n
While migrating to Kotlin 2 I get the error in a common-only project:
Copy code
> Task :...:kspCommonMainKotlinMetadata FAILED
e: -api-version (2.0) cannot be greater than -language-version (1.9)
But I set both the language version and the API version to 2.0 in the parent Gradle project, at the same source code location in the build script. Nevertheless, I tried to set the version directly in the subproject with several methods, none of them works. For example like it is in the documentation:
Copy code
tasks.named<KotlinCompilationTask<*>>("compileKotlin").configure {
    compilerOptions {
        apiVersion.set(KOTLIN_2_0)
        languageVersion.set(KOTLIN_2_0)
    }
}

// ERROR: Task with name 'compileKotlin' not found in project ...
Using a similar Gradle task based method:
Copy code
tasks.withType<KotlinCompilationTask<*>>().configureEach {
    compilerOptions {
        apiVersion.set(KOTLIN_2_0)
        languageVersion.set(KOTLIN_2_0)
    }
}

// Doesn't work
And also in the config block:
Copy code
kotlin {
    compilerOptions {
        apiVersion.set(KOTLIN_2_0)
        languageVersion.set(KOTLIN_2_0)
    }
}

// Doesn't work
Kotlin version: 2.0.20.RC2 Thanks.
I decided to delay the migration, maybe the final 2.0.20 version will work :(
m
Are you using KSP? KSP might change some of these unless you’re also using
useKSP2 = true
n
Thanks @mbonnin for the tip! Yes, I use KSP extensively, I will try to set this flag next time!
s
KSP2 is more than old KSP now with the Kotlin2-compiler.
Unlike KSP 1.x, it is no longer a compiler plugin and is built on the same set of Kotlin compiler APIs shared with IntelliJ IDEA, Android Lint, etc. Compared to the compiler-plugin approach, this allows a finer control of the program life cycle, simplifies KSP’s implementation and is more efficient. It is also a response to the compiler migration to K2, whose compiler plugin API is different from the one KSP1 uses.
from Introduction to KSP2 (Beta) You probably have to adapt all of your KSP-plugins.
🙏 1
😞 1