I've been struggling to get a Kotlin Multiplatform...
# javascript
w
I've been struggling to get a Kotlin Multiplatform project working with Gradle, and I've run out of ideas. Currently, I can do a
gradle build
immediately after a
gradle clean
, but if I then make a change to any Kotlin code in the JS source set, the next
gradle build
will fail.
The multiplatform project includes common, JVM, and JS source sets. The JS set has NPM dependencies on React via the kotlin-react library. On the second
gradle build
(when it fails), the error is that it can't resolve the Kotlin
import react.*
statements
t
Do you use
kotlin-wrappers
?
w
Several of them. Here's the entire
dependencies
section for that source set:
Copy code
dependencies {
  implementation(kotlin("stdlib-js"))
  implementation("org.jetbrains.kotlinx:kotlinx-html-js:0.6.4")
  implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.3.5")
  implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:0.20.0")

  implementation(npm("@fortawesome/fontawesome-svg-core", "^1.2.27"))
  implementation(npm("@fortawesome/free-solid-svg-icons", "^5.12.1"))
  implementation(npm("@fortawesome/react-fontawesome", "^0.1.9"))
  implementation(npm("@jetbrains/kotlin-css", "^1.0.0-pre.91"))
  implementation(npm("@jetbrains/kotlin-css-js", "^1.0.0-pre.91"))
  implementation(npm("@jetbrains/kotlin-extensions", "1.0.1-pre.91"))
  implementation(npm("@jetbrains/kotlin-react", "16.9.0-pre.91"))
  implementation(npm("@jetbrains/kotlin-react-dom", "^16.9.0-pre.91"))
  implementation(npm("@jetbrains/kotlin-react-redux", "^5.0.7-pre.91"))
  implementation(npm("@jetbrains/kotlin-react-router-dom", "^4.3.1-pre.91"))
  implementation(npm("@jetbrains/kotlin-redux", "4.0.0-pre.91"))
  implementation(npm("react", "^16.0.0-0"))
  implementation(npm("react-dom", "^16.0.0"))
  implementation(npm("react-redux", "5.0.7"))
  implementation(npm("react-router-dom", "4.3.1"))
  implementation(npm("redux", "^4.0.0-0"))
  implementation(npm("universal-cookie", "^4.0.3"))
  implementation(npm("victory", "^34.1.3"))
  implementation(npm("html-webpack-plugin", "^4.2.0"))
}
ah! You gave me the clue I needed! This was originally a project generated by
create-react-kotlin-app
that I migrated to a gradle build. It hadn't occurred to me that I needed to switch from the NPM packages of
kotlin-wrappers
to the Bintray artifacts. Making that change has my builds running smoothly now
t
Yes, since
pre.103
you can: 1. Declare wrappers only, npm dependencies will be added automatically 2. Remove
kotlin-css-js
dependency (not required anymore). 3. Remove
kotlin-html-js
- it already declared in wrappers
❤️ 1
🤩 1
w
Thank you. I'm still on
pre.91
for the time being, but I'll be migrating that forward
t
4.
coroutines
and
serialization
dependencies can be removed too, compatible versions already declared in
kotlin-redux
and
kotlin-react
dependencies
i
Better to declare
kotlin-react
and other dependencies form
kotlin-wrappers
via Gradle dependencies, not NPM https://youtrack.jetbrains.com/issue/KT-35197