How can I use enforcePlatform
function in Kotlin multiplatform?
This works well:
plugins {
kotlin("js")
}
dependencies {
fun kotlinw(target: String): String =
"org.jetbrains.kotlin-wrappers:kotlin-$target"
implementation(enforcedPlatform(kotlinw("wrappers-bom:1.0.0-pre.341")))
implementation(kotlinw("react"))
implementation(kotlinw("react-dom"))
implementation(kotlinw("css"))
implementation(kotlinw("react-router-dom"))
}
kotlin {
js(IR) {
browser {
commonWebpackConfig {
cssSupport.enabled = true
}
}
binaries.executable()
}
}
This reports an error Unresolved reference: enforcedPlatform
:
plugins {
kotlin("multiplatform")
}
kotlin {
js(IR) {
browser {
commonWebpackConfig {
cssSupport.enabled = true
}
}
}
sourceSets {
val jsMain by getting {
dependencies {
fun kotlinw(target: String): String =
"org.jetbrains.kotlin-wrappers:kotlin-$target"
implementation(enforcedPlatform(kotlinw("wrappers-bom:1.0.0-pre.341")))
implementation(kotlinw("react"))
implementation(kotlinw("react-dom"))
implementation(kotlinw("css"))
implementation(kotlinw("react-router-dom"))
}
}
}
}
I'm aware that this works in a multiplatform project, but the aim is not having to specify the version for each kotlin-wrappers dependency.
fun kotlinw(target: String): String =
"org.jetbrains.kotlin-wrappers:kotlin-$target-pre.341"
implementation(kotlinw("react:18.1.0"))
implementation(kotlinw("react-dom:18.1.0"))