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

gregorbg

08/17/2020, 9:36 PM
Hey! Are there any good resources on how to split different multiplatform targets into different Gradle modules/projects? I have an existing Gradle build with
projectRoot/frontend
(JS) and
projectRoot/backend
(JVM) as individual modules and I'd like to migrate to Kotlin without changing the project structure too much
a

andylamax

08/17/2020, 11:09 PM
just add
projectRoot/core
with it's
gradle
file, in
settings.gradle
add
include(":core")
, then in
projectRoot/frontend
and
projectRoot/backend
add
Copy code
dependencies {
  implementation(project(":core"))
}
You'll be all set
g

gregorbg

08/19/2020, 9:22 AM
Uhm, I don't quite follow how that solves the Kotlin side of things. What you're suggesting is the exact Gradle project setup that I'd like to achieve, but it misses out on the Kotlin part. I'll be a little more specific. The default
kotlin-multiplatform
template in IDEA gives me a project structure like this:
Copy code
projectRoot
  src
    commonMain
    commonTest
    jvmMain
    jvmTest
    jsMain
    jsTest
  build.gradle.kts (defines kotlin("multiplatform") plugin)
What I want is something along those lines:
Copy code
projectRoot
  core
    src
      main
      test
    build.gradle.kts (defines the common part of the multiplatform plugin)
  frontend
    src
      main
      test
    build.gradle.kts (defines the JS part of multiplatform, perhaps just using Kotlin/JS)
  backend
    src
      main
      test
    build.gradle.kts (defines the JVM part of multiplatform, perhaps just using Kotlin/JVM)
  build.gradle.kts (ties all the three subprojects together)
a

andylamax

08/19/2020, 9:33 AM
You are close to making it work. You only miss the multiplatform part, as your sources don't match kotlin mpp's structure. The best you could do is
Copy code
projectRoot
  core
    src
      commonMain
      commonTest
    build.gradle.kts [kotlin("multiplatform")]
  frontend
    src
      main
      test
    build.gradle.kts
       kotlin("js")
       dependencies {
           implementation(project(":core"))
       }
  backend
    src
      main
      test
    build.gradle.kts
       kotlin("jvm")
       dependencies {
           implementation(project(":core"))
       } 
  build.gradle.kts
  settings.gradle.kts
       include(":core")
       include(":frontend")
       include(":backend")
g

gregorbg

08/19/2020, 1:34 PM
Thanks, that did the trick!
a

andylamax

08/19/2020, 5:19 PM
Your welcome mate
2 Views