我正在使用 Kotlin 多平台(JVM 和 JS),它在 IDEA 中创建了三个项目demo
:demo-js
和demo-jvm
.
我想将通用代码拆分为更多的子项目/子模块。假设我添加commonmod
;我如何使它编译?
对于 , 现在的错误gradle run -p demo-jvm
是:
demo/demo-js/src/main/kotlin/demo/commonmod/example.kt: (3, 12): Actual function 'getPlatform' has no corresponding expected declaration
但我认为我这样做从根本上是错误的,因为我不知道什么应该取决于什么(尽管我尝试了很多迭代)。如果我解决了这个错误,我会得到其他错误,然后再得到其他错误,直到我回到这个错误。
作为一个最小但仍然很大的例子,我有:
演示/settings.gradle:
rootProject.name = 'demo'
include 'demo-jvm', 'demo-js', '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(':commonmod')
}
演示/演示-jvm/settings.gradle:
rootProject.name = '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"
}
演示/演示-js/settings.gradle:
rootProject.name = '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"
}
演示/commonmod/settings.gradle:
rootProject.name = 'demo'
include 'demo-jvm', 'demo-js'
演示/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')
}