我正在尝试在第一步中构建一个针对 linuxX64 的 Kotlin Multiplatform 命令行应用程序。因此,我想构建一个基于通用模块中使用的 Ktor 的客户端。
这是我相当简单的设置:
版本概述
- 克托尔 1.1.5
- Kotlin 多平台 1.3.31
- 摇篮 5.3.1
构建.gradle.kts
plugins {
kotlin("multiplatform") version "1.3.31"
}
repositories {
mavenCentral()
maven { url = uri("https://kotlin.bintray.com/ktor") }
}
kotlin {
linuxX64("linux") {
binaries {
executable()
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation(kotlin("stdlib-common"))
api("io.ktor:ktor-client-core:1.1.5")
}
}
val linuxMain by getting {
dependsOn(commonMain)
dependencies {
api("io.ktor:ktor-client-curl:1.1.5")
}
}
}
}
src/linuxMain/kotlin/Main.kt
fun main(){
val client = MyClient()
client.execute()
}
src/commonMain/kotlin/MyClient.kt
import io.ktor.client.*
class MyClient {
private val client = HttpClient()
fun execute() {
//do something with Ktor client
}
}
当我构建项目时,我得到以下构建问题:
11:15:21: Executing task 'build'...
> Configure project :
Kotlin Multiplatform Projects are an experimental feature.
> Task :wrapper
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
> Configure project :
Kotlin Multiplatform Projects are an experimental feature.
> Task :compileKotlinLinux FAILED
e: .../src/commonMain/kotlin/MyClient.kt: (1, 8): Unresolved reference: io
e: .../src/commonMain/kotlin/MyClient.kt: (5, 26): Unresolved reference: HttpClient
我是 Kotlin Native/Mutliplatform 和 Ktor 的新手。如果我的设置有误,请耐心等待...