https://kotlinlang.org logo
#ktor
Title
# ktor
a

Alexander Suraphel

01/14/2022, 2:09 PM
I’m trying to respond with JSON while following with these dependencies on my project . However I cannot import
ContentNegotiation
. Am I missing a dependency?
a

Aleksei Tirman [JB]

01/14/2022, 2:12 PM
How does your
build.gradle
file looks like? The following setup works for me:
Copy code
ext.ktor_version = "1.6.7"

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib"

    implementation "io.ktor:ktor-server-core:$ktor_version"
    implementation "io.ktor:ktor-server-netty:$ktor_version"
    implementation "ch.qos.logback:logback-classic:1.2.3"
    implementation "io.ktor:ktor-serialization:$ktor_version"

    testImplementation "io.ktor:ktor-server-test-host:$ktor_version"
    testImplementation "org.jetbrains.kotlin:kotlin-test"
}
a

Alexander Suraphel

01/14/2022, 2:14 PM
@Aleksei Tirman [JB]
implementation "org.jetbrains.kotlin:kotlin-stdlib"
is the only thing i’m missing and it’s not mentioned in the tutorials
a

Aleksei Tirman [JB]

01/14/2022, 2:14 PM
Btw, the ContentNegotiation is from
io.ktor.features
package.
a

Alexander Suraphel

01/14/2022, 2:14 PM
How do i install that please?
a

Aleksei Tirman [JB]

01/14/2022, 2:15 PM
Do you mean to install the ContentNegotiation plugin?
a

Alexander Suraphel

01/14/2022, 2:16 PM
yes it’s not mentioned anywhere in: https://ktor.io/docs/creating-http-apis.html
a

Aleksei Tirman [JB]

01/14/2022, 2:16 PM
There are links for the template and final projects at the top
a

Alexander Suraphel

01/14/2022, 2:17 PM
I tried to do import io.ktor.features.* but the package is not in my classpath
a

Aleksei Tirman [JB]

01/14/2022, 2:17 PM
Could you please share an archive with your project?
a

Alexander Suraphel

01/14/2022, 2:18 PM
My ktor version is 2.0.0-beta-1 if that helps
just followed the wizard
a

Aleksei Tirman [JB]

01/14/2022, 2:19 PM
Then you should consult docs for 2.0.0.
The documentation you mentioned is for version 1 of Ktor
a

Alexander Suraphel

01/14/2022, 2:19 PM
Got it
Thanks
One more thing @Aleksei Tirman [JB] I don’t know which
install
to import. There are a lot of options!
install(ContentNegotiation)
i retyped it and IntelliJ inferred it was from
io.ktor.server.application
👌 1
2 Views