Did anyone implement a build logic convention for ...
# multiplatform
a
Did anyone implement a build logic convention for KMP? I’ve tried to build one, but the build fails complaining that plugins with ID: “org.jetbrains.kotlin.plugin.serialization” and “com.google.devtools.ksp” cannot be found. I’m using InteliJ community edition. In my Kotlin Multiplatform plugin, I’m adding them like:
Copy code
apply(libs.findPlugin("kotlin.multiplatform").get().get().pluginId)
                apply(libs.findPlugin("android.library").get().get().pluginId)
                apply(libs.findPlugin("kotlin.serialization").get().get().pluginId)
                apply(libs.findPlugin("ksp").get().get().pluginId)
libs
is from version catalog. Multiplatform and Android library plugins seem to don’t have the issue. Any ideas?
h
Instead using
findPlugin
add the plugins to your build logic classpath and just use the id, its way easier: https://github.com/hfhbd/kotlinx-uuid/tree/main/gradle/build-logic
👍 3
a
I’ve tried using directly the id, instead of
findPlugin
, but still the same error. Thanks for the source, I’ll take a look. Maybe I’m implementing the
Plugin
interface wrongly, I see you’re not using it.
a
I suspect you need to add the plugins as dependencies to the build logic project. When you apply a plugin using an ID and the build script
plugins {}
block, then Gradle will do some behind-the-scenes magic to automatically add the plugin to the build script classpath. But if you use the
apply()
method, without the
plugins {}
block, then you need to add the plugins to the build script classpath.
h
Nope, I use the precompiled script plugins feature (applied with
kotlin-dsl
) to have the same DevEx comparing to "normal" build.gradle.kts allowing code sharing and reduces complexity.
👍 1
a
sorry, I was replying to Ana not you Philip. Your project looks good :)
👍 1
h
I know, me too 🙂
👍 1
a
d'oh 😅
there's like 10 different ways to add plugins in Gradle, it's confusing
👍 1
a
thank you both, I’ve added these two plugins via
implementation
in
dependencies
of
build.gradle.kts
. Seems that the problem is resolved now. I agree that Philip’s approach is simpler, I’ll try to re-implement with it.
👍 1
Seems like for unknown reason I cannot use the
kotlin {}
block in my plugin gradle script. I’m adding the kotling jvm plugin:
Copy code
dependencies {
    implementation(libs.plugins.kotlin.jvm.toDep())
}
however, the build is failing with:
Copy code
Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 
public fun DependencyHandler.kotlin(module: String, version: String? = ...): Any defined in org.gradle.kotlin.dsl
public fun PluginDependenciesSpec.kotlin(module: String): PluginDependencySpec defined in org.gradle.kotlin.dsl
h
You are using Kotlin Multiplatform, so I guess you have to use
implementation(libs.plugins.kotlin.multiplatform.toDep())
but it depends on your libs.versions.toml entry.
👍 1
a
Still the same error, but I’ll dig deeper, thank you 🙂