首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用ktor修复“未解决的引用:HttpClient”-客户端-核心目标linuxX64

如何用ktor修复“未解决的引用:HttpClient”-客户端-核心目标linuxX64
EN

Stack Overflow用户
提问于 2019-05-11 09:40:58
回答 1查看 4.2K关注 0票数 2

我正试图在第一步构建一个针对linuxX64的Kotlin多平台命令行应用程序。因此,我想构建一个基于Ktor的客户端,该客户端用于公共模块。

在这里,我非常简单的设置:

版本概述

  • Ktor 1.1.5
  • Kotlin多平台1.3.31
  • 5.3.1级

build.gradle.kts

代码语言:javascript
复制
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

代码语言:javascript
复制
fun main(){
    val client = MyClient()
    client.execute()
}

src/commonMain/kotlin/MyClient.kt

代码语言:javascript
复制
import io.ktor.client.*

class MyClient {

    private val client = HttpClient()

    fun execute() {
        //do something with Ktor client
    }
}

在构建项目时,会遇到以下生成问题:

代码语言:javascript
复制
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原住民/Mutliplatform和Ktor的新手。所以请原谅我如果我的设置是错的..。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-11 10:40:15

settings.gradle.kts添加enableFeaturePreview("GRADLE_METADATA")解决了构建问题。我刚刚成功地使用linuxX64二进制文件调用了ktor-client-curl :-)

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56089071

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档