https://kotlinlang.org logo
#gradle
Title
# gradle
j

John O'Reilly

09/30/2023, 1:47 PM
I might have missed it but couldn't find this asked before......is there example of how to use different versions of Kotlin in a multi-module KMP project? I can do something like following perhaps but in this case I need to use different versions of multiplatform one in different modules
Copy code
resolutionStrategy {
    eachPlugin {
        if (requested.id.id == "org.jetbrains.kotlin.android") {
            useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.20-Beta2")
        }
        if (requested.id.id == "org.jetbrains.kotlin.multiplatform") {
            useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.10")
        }
    }
}
m

mbonnin

09/30/2023, 1:53 PM
That sounds risky as 2 different KPG versions will clash if they ever end up in the same classloader
But why not use
1.9.20-Beta2
everywhere?
j

John O'Reilly

09/30/2023, 1:54 PM
I have a Wasm based Compose for Web module that right now will only work with older version of Kotlin
m

mbonnin

09/30/2023, 1:57 PM
You could try loading different KGP versions in different submodules (instead of loading a single version in
buildSrc
/`root/build.gradle.kts` ) but TBH this sounds like it'll add more issue than it will solve
j

John O'Reilly

09/30/2023, 1:58 PM
Also this will probably only work while the wasm module isn't using shared kmp code given both of them are using
kotlin("multiplatform")
plugin
(assuming main shared module is using later version)
can use following approach for iOS client....unless something sort of similar could be done in this case based on which client/module is being built/run https://johnoreilly.dev/posts/kmm-using-different-kotlin-versions/
5 Views