Trying to update to Gradle 9.4 and getting ```A pr...
# community-support
e
Trying to update to Gradle 9.4 and getting
Copy code
A problem occurred configuring project ':buildSrc'.
> Could not resolve all artifacts for configuration 'classpath'.
   > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin-api:2.2.21
 Required by:
         buildscript of project ':buildSrc' > org.jetbrains.kotlin.plugin.serialization:org.jetbrains.kotlin.plugin.serialization.gradle.plugin:2.2.21 > org.jetbrains.kotlin:kotlin-serialization:2.3.0 > org.jetbrains.kotlin:kotlin-gradle-plugins-bom:2.3.0> Unable to find a variant with the requested capability: coordinates 'org.jetbrains.kotlin:kotlin-gradle-plugin-api-gradle813':
           - Variant 'apiElementsWithFixedAttribute' provides 'org.jetbrains.kotlin:kotlin-gradle-plugin-api:2.3.0'
           - Variant 'gradle80ApiElements' provides 'org.jetbrains.kotlin:kotlin-gradle-plugin-api:2.3.0'
           - Variant 'gradle80JavadocElements' provides 'org.jetbrains.kotlin:kotlin-gradle-plugin-api:2.3.0'
           - Variant 'gradle80RuntimeElements' provides 'org.jetbrains.kotlin:kotlin-gradle-plugin-api:2.3.0'
Is Kotlin 2.3 minimum for Gradle 9.4?
Let me see the compatibility table
Not sure, we are not using Kotlin 2.3 yet and in the compatibility matrix I see opposite linking - minimum Gradle version to support specific kotlin version
I don't have any kotlin dependency in
buildSrc
only kotlin coroutines and serialisation
m
Works for me in a simple project
It's
9.4.0-rc-1
, right?
9.4.0
isn't out yet AFAIK
e
Yeah
m
Copy code
org.jetbrains.kotlin.plugin.serialization:org.jetbrains.kotlin.plugin.serialization.gradle.plugin:2.2.21 > org.jetbrains.kotlin:kotlin-serialization:2.3.0
That's interesting. Something is upgrading your version of the serialization plugin
e
Let me try check dependency
m
You can run something like
Copy code
./gradlew -p buildSrc buildEnvironment
Or dependencies too
But looks like this is more of a
buildEnvironment
thing
e
I can not run anything since configuration fails
m
Even in buildSrc?
What is your
buildSrc/build.gradle.kts
like?
e
Yeah, it looks like
Copy code
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    `java-gradle-plugin`
    `kotlin-dsl`
    alias(libs.plugins.android.lint)
    alias(libs.plugins.kotlin.serialization)
}

gradlePlugin {
  // bunch of our plugins
}

dependencies {
    implementation(libs.androidgradleplugin)
    implementation(libs.android.gradle.cache.fix)
    implementation(libs.kotlin.gradle.plugin)

    implementation(libs.kotlinpoet)

    implementation(libs.kotlinx.coroutines.core)
    implementation(libs.kotlinx.serialization.core)
    implementation(libs.kotlinx.serialization.json)
    implementation(libs.kotlinx.serialization.xml)
    implementation(platform(libs.retrofit.bom))
    implementation(libs.retrofit)
    implementation(libs.retrofit.converter.kotlinx.serialization)

    // phrase java client
    implementation(libs.phrase.java)
    // start of dependencies of phrase java client
    implementation(libs.javax.annotation.api)
    implementation(libs.findbugs)
    // added because DataDog needs newer version of okhttp
    implementation(platform(libs.okhttp.bom))
    implementation(libs.okhttp)
    implementation(libs.okhttp.logging.interceptor)
    implementation(libs.gson)
    implementation(libs.gson.fire)
    // end of dependencies of phrase java client

    testImplementation(libs.junit)

    lintChecks(libs.gradle.lint.rules)
}

tasks.withType(KotlinCompile::class.java) {
    compilerOptions {
        freeCompilerArgs.addAll(
            // Kotlin annotation changes <https://youtrack.jetbrains.com/issue/KT-73255>
            "-Xannotation-default-target=param-property",
            // If data class has private constructor then copy is private also
            "-Xconsistent-data-class-copy-visibility",
        )
    }
}
v
> That's interesting. Something is upgrading your version of the serialization plugin Not of the plugin. The plugin depends on
kotlin-serialization:2.3.0
which is an update from 2.2.21 for some reason
👍 1
m
Let's see if it's my dear friend
kotlin-dsl
e
Probably this is it
Copy code
`kotlin-dsl`
    alias(libs.plugins.kotlin.serialization)
One is serving newer kotlin and one is asking old kotlin
m
Yea
Replace `kotlin-dsl` with `libs.plugins.kotlin.jvm`
🙅‍♂️ 1
v
Or upgrade the serialization plugin
The new
kotlin-dsl
depends on 2.3.0, yes
To use the same version, you should be able to use
embeddedKotlinVersion
instead, but then without version catalog iirc
e
Oke, I can try to fix it, but does it mean we cook gradle wrong?
I mean gradle change log doesn't say anything about kotlin upgrade requirement and if many projects like us doing it then it will be big bang
Oke maybe not a big bang - only for projects mixing serialization or other kotlin dependent plugins
v
With
buildSrc
you develop build logic for the Gradle version that is running. So best is to use the embedded Kotlin version. The
kotlin-dsl
plugin does. But you apply a different version of the serialization plugin which might lead to a conflict here.
If you would have used the
embeddedKotlinVersion
for the serialization plugin, you might not have had the problem.
m
Yep. It's a kotlin problem, you can't have KGP 2.3 with the 2.2 serialization Gradle plugin
v
Or if you did not use
kotlin-dsl
as Martin suggests, even though I greatly dislike that suggestion in general
e
Oke, maybe time for us to update kotlin
m
Nowandroid uses kotlin dsl
Interestingly, they backtracked on precompiled script plugins because it was slow
They could certainly just use
embedded-kotlin
e
Thanks people, let me think. And looks like Gradle knows about it and no need to create an issue for them on Github. It is by design.
v
kotlin-dsl
is not identical to precompiled script plugins, not even to Kotlin DSL precompiled script plugins. That is just one aspect of
kotlin-dsl
. If you have a performance problem with precompiled Kotlin DSL script plugins, you can just use "normal" KT files to write the plugins, but you can still use
kotlin-dsl
for its other benefits. Even though you see the benefits as drawbacks, but you know that I greatly dislike that blog post and see it exactly the other way around than what is written there except for the performance thing if it is actually a problem for a project. 😉
m
Yep, agree to disagree!
Ok so I've just been hit by this now 🙂
rereads the whole backlog
How did you end up fixing it @Eug?
e
I didn't fix it yet. I mean I moved to build-logic but I still have warning about kotlin version and gradle dsl
👍 1
🙏 1
m
Turned out to be a bug. I'd wait for 9.4.1
👍 1