【发布时间】:2020-05-28 14:29:22
【问题描述】:
我想用 Kotlin Multiplatform 构建一个在 Linux、Macos 和 Windows 上运行的 CLI 工具。
但我正在努力设置我的build.gradle 和我的项目结构。我正在使用IntelliJ IDEA 2020.1 并使用File -> New -> Project -> Kotlin / Native | Gradle 创建了我的基本项目
目前我正在查看来自 kotlinlang.org 的指南,但我更容易跌倒而不是实现某些目标。
到目前为止,我的build.gradle 如下所示:
plugins {
id 'org.jetbrains.kotlin.multiplatform' version '1.3.72'
}
repositories {
mavenCentral()
}
kotlin {
// For ARM, should be changed to iosArm32 or iosArm64
// For Linux, should be changed to e.g. linuxX64
// For MacOS, should be changed to e.g. macosX64
// For Windows, should be changed to e.g. mingwX64
linuxX64("linux") {
}
mingwX64("mingw") {
}
macosX64("macos") {
binaries {
executable {
// Change to specify fully qualified name of your application's entry point:
entryPoint = 'sample.main'
// Specify command-line arguments, if necessary:
runTask?.args('')
}
}
}
sourceSets {
commonMain {
kotlin.srcDir('src/main')
resources.srcDir('src/res')
dependencies {
implementation kotlin('stdlib-common')
implementation "com.github.ajalt:clikt-multiplatform:2.7.0"
}
}
commonTest {
dependencies {
implementation kotlin('test-common')
implementation kotlin('test-annotations-common')
}
}
macosX64().compilations.test.defaultSourceSet {
dependsOn commonMain
}
// Note: To enable common source sets please comment out
'kotlin.import.noCommonSourceSets' property
// in gradle.properties file and re-import your project in IDE.
macosMain {
}
macosTest {
}
}
}
wrapper {
gradleVersion = "6.4.1"
distributionType = "ALL"
}
而且我的项目结构还是基本的:
以前我只使用 Kotlin 处理 Android 项目,我想我被 gradle 宠坏了,因为 Android 生成了最基本的东西,而且一切都正常工作而无需做太多。
我知道我需要创建像 linuxMain 和 mingwMain 这样的包,但是我应该将通用源集放在哪里?我尝试创建一个名为 commonMain 的包,但它甚至不允许我在该包中创建 Kotlin 文件。
完成后,我希望(在最好的情况下)一个公共源集和一个用于所有目标的入口点。这甚至可能吗?
【问题讨论】:
标签: kotlin gradle build.gradle kotlin-multiplatform kotlin-native