Hi, is it possible to add `kotlin-gradle-plugin` t...
# gradle
i
Hi, is it possible to add
kotlin-gradle-plugin
to
buildSrc
? My idea is to write reusable extensions of various gradle types to provide usages for multiple KMM modules. But no matter what I've tried it won't work. 1.
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.31")
fails with
Unable to load class 'com.android.build.gradle.BaseExtension'.
2. ``compileOnly("org.jetbrains.kotlinkotlin gradle plugin1.4.31")` fails latter down the line
Caused by: java.lang.ClassNotFoundException: org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
Here's the full
build.gradle.kts
for `buildSrc`:
Copy code
repositories {
    gradlePluginPortal()
    google()
    mavenCentral()
}

plugins {
    `kotlin-dsl`
}

dependencies {
    compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.31")
}

kotlinDslPluginOptions {
    experimentalWarning.set(false)
}
j
Yes you can, I use it with implementation. The first error is not related to Kotlin plugin but android gradle plugin.
i
Thanks! I managed to get it working like this:
Copy code
repositories {
    gradlePluginPortal()
    google()
    mavenCentral()
}

plugins {
    `kotlin-dsl`
}


dependencies {
        implementation("com.android.tools.build:gradle:4.1.2")
        implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.31")
}


kotlinDslPluginOptions {
    experimentalWarning.set(false)
}
Not ideal but it works 🙂
j
Try adding it
Copy code
"com.android.tools.build:gradle:4.1.3"
Really it is ideal, you need AGP in KMM projects, you can't avoid it
if the project was Multiplatform with no android, then you don't need AGP
i
I meant more because afaik there's no way to reusably specify target versions in one place, both for buildSrc as well as root
build.gradle.kts
j
What do you mean?
I specify all my versions in only one place 🤔
i
Would it be possible to do so even for
build.gradle.kts
of
buildSrc
? Can it reference
Versions.kt
defined in
buildSrc/src/Versions.kt
at that point?
j
if you are talking about the buildscript in the root build.gradle.kts, you don't need to add kotlin and Android anymore
i
No no, I meant the buildscript of
buildSrc
j
There is a trick based on having a buildSrc inside buildSrc
But it is easier to migrate to Gradle 7.0 and version catalogs
i
Buildsrception 🙂 Oh didn't know about those, thanks!
🙂 2