This message was deleted.
# community-support
s
This message was deleted.
c
Kotlin-dsl uses the embedded Kotlin version with Gradle, which isn’t yet 1.9
p
How does the kotlin-dsl use the embedded version if a higher version is available on the class path?
c
There should t be other versions on the class path. It’s problematic in several ways to mix kotlin-dsl with kotlin/jvm plugins, they serve different purposes.
Copy code
dependencies {
    implementation(libs.plugins.kotlin.jvm.toDep())
}
This isn’t advisable, it messes with the dependencies and Kotlin versions that Gradle depends on for Gradle-code.
I typically keep my Gradle code aligned with the Gradle versions that it targets (there is not yet any Gradle version that uses Kotlin 1.9) and bump the Gradle version occasionally (perhaps that brings a Kotlin version change as well). iirc there is a way to change the Kotlin language level for your Gradle code - on recent Gradle versions you could use some experimental features from 1.9 (such as data objects).
This is how the Kotlin language level is changed for my non-Gradle code, perhaps this would work in your build-logic/build.gradle.kts:
Copy code
tasks.withType<KotlinCompile>().configureEach {
    compilerOptions {
        languageVersion.set(KotlinVersion.KOTLIN_1_9)
    }
}
p
Hm, this would require to not use
implementation(kgp)
as plugin author too, otherwise you can get a new kgp transitively, won't it?
c
if you want to do something like that use the GAV coordinates, using
embeddedKotlinVersion
as the version to match everything up.
and consider using
compileOnly
such that consumers of your plugin could provide their own version, as the plugin could presumably run on different Gradle versions.
I have this in a settings.gradle for version catalog:
Copy code
plugin("gradle.kotlin.dslPlugins" to "org.gradle.kotlin.kotlin-dsl:$expectedKotlinDslPluginsVersion")
            plugin("jetbrains.kotlin.jvm" to "org.jetbrains.kotlin.jvm:$embeddedKotlinVersion")
lol, and this in a build script that should be using the version catalog:
Copy code
compileOnly(plugin("org.gradle.kotlin.kotlin-dsl", expectedKotlinDslPluginsVersion))
    compileOnly(plugin("org.jetbrains.kotlin.jvm", embeddedKotlinVersion))
p
Honestly, I didn't get it. Do you have a sample?
c
something like
compileOnly("org.jetbrains…:<kgp>:$embeddedKotlinVersion")
p
Yes, I tried it with the uploaded reproducer and this works well, but I failed to apply the changes my real project, which uses ksp having an implementation dependency to kgp. Excluding the kgp dep does not work, then the ksp fails during applying it in convention plugin because the kgp dependency (obviously) isn't available.
Or, I just wait until Gradle 8.3 is out containing Kotlin 1.9
e
I did this by adding a classpath dependency to KGP in the root build.gradle.kts
classpath(<kgp group>:<kgp name>:$embeddedKotlinVersion)
Then I added a
compileOnly
dependency to KGP with v1.9.0 to the project that needed it