https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
l

Lukasz Ciastko

09/29/2023, 11:20 AM
Hi. Maybe this is a stupid question, but I am really confused - how do I set a multiplatform version in my lubrary? So far I’ve been using:
Copy code
plugins {
    kotlin("multiplatform")
    kotlin("native.cocoapods")
    kotlin("plugin.serialization") version "1.6.10"
    id("com.android.library")
    id("maven-publish")
}
But now I need to make it explicit to use 1.9.10. I tried:
Copy code
plugins {
    kotlin("multiplatform") version "1.9.10"
    kotlin("native.cocoapods")
    kotlin("plugin.serialization") version "1.6.10"
    id("com.android.library")
    id("maven-publish")
}
But this results in an error:
Copy code
Error resolving plugin [id: 'org.jetbrains.kotlin.multiplatform', version: '1.9.10']
> Plugin request for plugin already on the classpath must not include a version
But I don’t specify the version anywhere else in my code. How does it figure out which version it’s using and how can I know which that is and how to change it?
k

krzysztof

09/29/2023, 11:22 AM
I’d suspect you have defined KMP version in either root build.gradle or settings.gradle
or in root build.gradle, you declare the plugin usage without specified version and it applies the latest one there is (potentially, not sure about it), so then specifying version in sub-module gets you this error
l

Lukasz Ciastko

09/29/2023, 11:25 AM
I am getting the Xcode 15 linker issue which was supposedly fixed in 1.9.10, so I don’t think it does use the latest… I don’t see a version configured anywhere.
Copy code
buildscript {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
    dependencies {
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10")
        classpath("com.android.tools.build:gradle:7.0.4")
    }
}
Would any of these dependencies have any impact on the Multiplatform version? Sorry, I’m more of an iOS developer, not really good with Gradle.
k

krzysztof

09/29/2023, 11:33 AM
I don’t see KMP plugin in your dependencies - where are those defined?
l

Lukasz Ciastko

09/29/2023, 11:37 AM
This is in my shared folder build.gradle.kts:
Copy code
import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFramework

plugins {
    kotlin("multiplatform")
    kotlin("native.cocoapods")
    kotlin("plugin.serialization") version "1.6.10"
    id("com.android.library")
    id("maven-publish")
}
l

Lukasz Ciastko

09/29/2023, 11:38 AM
It looks like adding this in the main build.gradle.kts might work:
Copy code
plugins {
    kotlin("multiplatform").version("1.9.10").apply(false)
}
I’m not sure because it complains about something else now that has changed .
@krzysztof it’s not root, it’s in the shared.
k

krzysztof

09/29/2023, 11:40 AM
There's a root (on project's root) build.gradle file where normally the plugins for the rest of modules are set. Setting the kmp plugin with version there will make sure rest of modules are using same version of plugin
l

Lukasz Ciastko

09/29/2023, 11:42 AM
Yeh, i can see it does it like this now. I created a new empty project and it works the way you’re describing. My project was created around 2 years ago and it looks completely different. I might just create a new project and copy over all the code.
k

krzysztof

09/29/2023, 11:43 AM
so in your root’s
build.gradle
you can set something like:
Copy code
// <https://youtrack.jetbrains.com/issue/KTIJ-19369>
@Suppress("DSL_SCOPE_VIOLATION")
plugins {
  // other plugins here
  kotlin("multiplatform").version("1.9.10").apply(false)
}
few things about this code: 1. The ‘@suppress’ there is to silence issue seen on lower version of Gradle 2.
apply(false)
to stop applying plugins automatically, unless submodule apply the plugin (not every sub-module require all the plugins)
👍 1
My project was created around 2 years ago
Ah, yeah, probably best to start over and just do copy-over, if not too big effort 😄
l

Lukasz Ciastko

09/29/2023, 1:48 PM
It looks like adding this:
Copy code
plugins {
    kotlin("multiplatform").version("1.9.10").apply(false)
}
to the top of build.gradle.kts in the shared folder helped. Anyway, thank you.
🙏 1
Now I need to deal with all the changes that happened in the last.2 years. 🙂
2 Views