Ktor - 我生成了一个新项目来尝试一下,但无法导入 CIO 引擎

Yuu*_*una 8 kotlin build.gradle ktor

我正在为一个项目尝试 Ktor,但 Ktor 插件生成的示例项目不起作用。CIO 引擎导入存在问题。

当我输入import io.ktor.client.engine.cio.*“未解析参考:cio”时

这是我的build.gradle

buildscript {
    ext.kotlin_version = '1.4.10'
    ext.ktor_version = '1.4.0'

    repositories {
        jcenter()
    }
    
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

apply plugin: 'kotlin'
apply plugin: 'application'

sourceCompatibility = 1.8
compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

kotlin {
    experimental {
        coroutines "enable"
    }
}

group 'com.archilog_rest'
version '0.0.1'
mainClassName = "io.ktor.server.tomcat.EngineMain"

sourceSets {
    main.kotlin.srcDirs = main.java.srcDirs = ['src']
    test.kotlin.srcDirs = test.java.srcDirs = ['test']
    main.resources.srcDirs = ['resources']
    test.resources.srcDirs = ['testresources']
}

repositories {
    mavenLocal()
    jcenter()
    maven { url 'https://kotlin.bintray.com/kotlinx' }
}

dependencies {
    println(ktor_version)
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    implementation "io.ktor:ktor-server-tomcat:$ktor_version"
    implementation "ch.qos.logback:logback-classic:$logback_version"
    implementation "io.ktor:ktor-server-core:$ktor_version"
    implementation "io.ktor:ktor-server-sessions:$ktor_version"
    implementation "io.ktor:ktor-client-core:$ktor_version"
    implementation "io.ktor:ktor-client-core-jvm:$ktor_version"
    implementation "io.ktor:ktor-client-cio:$ktor_version"
    implementation "io.ktor:ktor-client-auth-jvm:$ktor_version"
    implementation "io.ktor:ktor-client-json-jvm:$ktor_version"
    implementation "io.ktor:ktor-client-gson:$ktor_version"
    implementation "io.ktor:ktor-websockets:$ktor_version"
    implementation "io.ktor:ktor-client-websockets:$ktor_version"
    testImplementation "io.ktor:ktor-server-tests:$ktor_version"
}
Run Code Online (Sandbox Code Playgroud)

我真的不明白为什么会出错,因为我几乎没有对样本做任何事情......

编辑: 在查看如何导入 CIO 后,我注意到build.gradle它是

implementation "io.ktor:ktor-client-cio:$ktor_version"
Run Code Online (Sandbox Code Playgroud)

代替:

implementation "io.ktor:ktor-client-cio-jvm:$ktor_version"
Run Code Online (Sandbox Code Playgroud)

有点奇怪,但现在可以了

Abd*_*ato 2

是的,使用implementation "io.ktor:ktor-client-cio:$ktor_version"肯定能解决你的问题。

我今天也遇到了同样的问题,但是读完你的问题后,我发现了我的错误。谢谢。