How can a Kotlin/JS gradle subproject depend on a ...
# multiplatform
j
How can a Kotlin/JS gradle subproject depend on a Kotlin/Multiplatform subproject ? In my case I have the following gradle project structure:
Copy code
client/               <= Kotlin/JS subproject
 |- build.gradle.kts  <= What should I put here to allow client to depend on :shared ?
server/               <= Kotlin/JVM subproject
 |- build.gradle.kts  <= What should I put here to allow server to depend on :shared ?
shared/               <= Kotlin/Multiplatform subproject
 |- build.gradle.kts
I tried to put this but it didn't work:
Copy code
dependencies {
    implementation(project(":shared"))
}
e
What do you mean by “it didn’t work”?
j
It fails with
Copy code
Could not determine the dependencies of task ':client:packageJson'.
> project ':shared' is not configured for JS usage
e
Does the dependency work in the
server
project? I.e. is it a JS-only issue?
j
Yes, it does work with the
server
project (I didn't actually try because it was not working with JS, so thanks for the question 🙂 )
e
See if you can work around it by publishing the multiplatform module to Maven Local and consuming it from there, instead of having a
project()
dependency - this might work. If not, I’d file a Youtrack issue.
Also, since publishing multiplatform projects requires Gradle metadata support, make sure you’re either on Gradle 6.x or have
enableFeaturePreview("GRADLE_METADATA")
in your
settings.gradle
.
r
The error sounds like you're missing a js target in your
shared
module
Copy code
kotlin {
  ...
  js {
    browser() // and/or nodejs()
  }
}
👍 1
j
Indeed, adding this made the trick! I had the
js {}
block but not the
browser()
line. Thanks 🙂
e
Good catch! Perhaps the error message could be better.
i