I'm using Kotlin multi-platform (JVM & JS), which in IDEA creates three projects: demo
, demo-js
and demo-jvm
.
I would like to split the common code into more subprojects/submodules. Let's say I add commonmod
; how do I make it compile?
The error right now, for gradle run -p demo-jvm
, is:
demo/demo-js/src/main/kotlin/demo/commonmod/example.kt: (3, 12): Actual function 'getPlatform' has no corresponding expected declaration
but I think I'm doing this fundamentally wrong, as I don't know what should depend on what (although I tried quite some iterations). If I solve this error I get other ones, and then other ones again, until I'm back to this one.
As a minimal-but-still-large example, I have:
demo/settings.gradle:
rootProject.name = 'demo'
include 'demo-jvm', 'demo-js', 'commonmod'
demo/build.gradle:
buildscript { ... }
apply plugin: 'kotlin-platform-common'
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-test-annotations-common:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-test-common:$kotlin_version"
compile project(':commonmod')
}
demo/demo-jvm/settings.gradle:
rootProject.name = 'demo'
demo/demo-jvm/build.gradle:
buildscript { ... }
apply plugin: 'kotlin-platform-jvm'
apply plugin: 'application'
repositories {
mavenCentral()
}
mainClassName = "demo.MainKt"
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
expectedBy project(":")
testCompile "junit:junit:4.12"
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
}
demo/demo-js/settings.gradle:
rootProject.name = 'demo'
demo/demo-js/build.gradle:
buildscript { ... }
apply plugin: 'kotlin-platform-js'
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
expectedBy project(":")
testCompile "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version"
}
demo/commonmod/settings.gradle:
rootProject.name = 'demo'
include 'demo-jvm', 'demo-js'
demo/commonmod/build.gradle:
buildscript { ... }
apply plugin: 'kotlin-platform-common'
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-test-annotations-common:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-test-common:$kotlin_version"
compile project(':demo-js')
compile project(':demo-jvm')
}