I'm trying Ktor for a project but the sample project generated by the Ktor plugin does not work. There is a problem with the CIO engine import.
When I put import io.ktor.client.engine.cio.*
it says "Unresolve reference: cio"
Here is my 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"
}
I don't really understand why it goes wrong since I did nearly nothing from the sample...
Edit:
After looking how to import CIO I noticed in my build.gradle
it was
implementation "io.ktor:ktor-client-cio:$ktor_version"
instead of:
implementation "io.ktor:ktor-client-cio-jvm:$ktor_version"
Kinda weird but it works now
Yes, using
implementation "io.ktor:ktor-client-cio:$ktor_version"
will definitely solve your problem.I've faced the same problem today, but after reading your question, I found my mistake. Thanks.