I have this plugins block in my build.gradle.kts f...
# gradle
t
I have this plugins block in my build.gradle.kts for my KMP module:
Copy code
plugins {
    id("com.android.library")
    kotlin("multiplatform")
    kotlin("native.cocoapods")
    kotlin("plugin.serialization") version "1.4.30"
    id("com.chromaticnoise.multiplatform-swiftpackage") version "2.0.3"
}
which gives me this error in AS:
Copy code
Error resolving plugin [id: 'org.jetbrains.kotlin.plugin.serialization', version: '1.4.30']
> Plugin request for plugin already on the classpath must not include a version
it works if I remove the version, but then fails when I do the iOS framework build. The serialzation github page shows to include the version. What is the issue here?
t
is your project public?
t
I am afraid not.
t
what is the error when you remove version and build ios?
t
Copy code
Showing All Messages
* Where:

Build file '/Users/tylerwilson/Projects/salonbiz-library/build.gradle.kts' line: 13



* What went wrong:

Plugin [id: 'org.jetbrains.kotlin.plugin.serialization', artifact: 'org.jetbrains.kotlin:kotlin-serialization:null'] was not found in any of the following sources:
Which appears to be going through the settings.gradle.kts pluginManagement/resolutionStrategy here:
Copy code
when (requested.id.id) {
                "kotlin-multiplatform", "org.jetbrains.kotlin.multiplatform", "org.jetbrains.kotlin.native.cocoapods" ->
                    useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.30")
                "kotlinx-serialization", "org.jetbrains.kotlin.plugin.serialization" ->
                    useModule("org.jetbrains.kotlin:kotlin-serialization:${requested.version}")
            }
t
if you have such block in
settings.gradle.kts
- then you don't need to define version in any project
build.gradle.kts
t
But if I don’t, I get that error when building iOS
I guess I could hard-code that value there.
t
btw have you considered just using
pluginManagement
in settings? Something like this (note it is in Groovy):
Copy code
pluginManagement {
  repositories {
    mavenCentral()
    gradlePluginPortal()
  }

  plugins {
    id 'org.jetbrains.kotlin.jvm' version "1.4.30"
    id 'com.github.johnrengelman.shadow' version '6.1.0'
  }
}
t
this was mentioned in a previous thread i made, and others made fun of me for having a plugins block in settings 😕. so many ways to do things in gradle..
🤗 1
c
plugins { kotlin(“multiplatform”) kotlin(“plugin.serialization”) id(“com.android.library”) id(“kotlin-android-extensions”) id(“com.squareup.sqldelight”) version “1.4.2" } This is inside of my common gradle
t
and what is your settings?
c
pluginManagement { repositories { gradlePluginPortal() google() jcenter() mavenCentral() } resolutionStrategy { eachPlugin { if (requested.id.namespace == “com.android” || requested.id.name == “kotlin-android-extensions”) { useModule(“com.android.tools.build: gradle :4.0.1”) } } } } rootProject.name = “ChipEn” include(“:android”) include(“:common”) enableFeaturePreview(“GRADLE_METADATA”)
t
I don't see a problem of defining plugins in settings (if you are not using
buildSrc
module)
1
c
As soon as it works man
🤣 1
t
cool, thanks. i removed the version from build.gradle.kts and hard-coded the version in settings.gradle.kts, and that seems to work in both places. would be nice if that could be a var, but that did not work for me either. but it works now, so won’t have to change until 1.4.31. 😉
👍 2
v
Why should someone make fun of you for having a plugins block in pluginManagement in the settings script? That's exactly the place where you define a default version for the pluign so that it is used in all build scripts where you don't specify a different version explicitly.
t
Perhaps I overstated it. I think the issue is that there are so many ways of doing things in gradle, and there are so few good canonical examples for some use cases (that I have found).
but it works now, so won’t have to change until 1.4.31. 😉
And then I just saw they released 1.4.31. Funny (?)
v
There are usually not too much ways to do one thing. It always is a question of the exact use-case actually.
t
thank you, I will read that over. i still do the bare minimum in gradle. i have two apps with two shared libs, one shared to three iOS App too. So I am unsure of the flow and how settings, build, buldSrc all work. Gotta keep reading…
v
We are also always here to help if you have questions or doubts on how to do something 🙂 Keep in mind that often it helps if you can knit a small MCVE, especially if you cannot share your project.
t
Very much appreciated! Thank you.
v
Oh, we are on the Kotlin Slack, ... You can also join the Gradle Community Slack for Gradle related things, there might be more Gradle-cracks around than here sometimes. 😄
Or of course the Gradle forums