如何使用针对 linuxX64 的 ktor-client-core 修复 'Unresolved reference: HttpClient'
How to fix 'Unresolved reference: HttpClient' with ktor-client-core targeting linuxX64
我正在尝试在第一步中构建一个针对 linuxX64 的 Kotlin 多平台命令行应用程序。所以我想基于公共模块中使用的Ktor构建一个客户端。
这是我相当简单的设置:
版本概览
- Ktor 1.1.5
- Kotlin 多平台 1.3.31
- Gradle 5.3.1
build.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 的新手。如果我的设置有误,请耐心等待...
将 enableFeaturePreview("GRADLE_METADATA")
添加到 settings.gradle.kts 修复了构建问题。
我刚刚使用 ktor-client-curl 使用 linuxX64 二进制文件进行了一次成功的 HTTP 调用 :-)
我正在尝试在第一步中构建一个针对 linuxX64 的 Kotlin 多平台命令行应用程序。所以我想基于公共模块中使用的Ktor构建一个客户端。
这是我相当简单的设置:
版本概览
- Ktor 1.1.5
- Kotlin 多平台 1.3.31
- Gradle 5.3.1
build.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 的新手。如果我的设置有误,请耐心等待...
将 enableFeaturePreview("GRADLE_METADATA")
添加到 settings.gradle.kts 修复了构建问题。
我刚刚使用 ktor-client-curl 使用 linuxX64 二进制文件进行了一次成功的 HTTP 调用 :-)