After upgrading Ktor to 2.0.0, I see this error in...
# ktor
r
After upgrading Ktor to 2.0.0, I see this error in IntelliJ only (no error when building from gradle):
Copy code
Cannot access class 'kotlinx.serialization.json.Json'. Check your module classpath for missing or conflicting dependencies
when I try to use content negotiation:
Copy code
install(ContentNegotiation) {
        json(json)
    }
I checked the dependencies but I can't see any obvious conflicts.
I see also this error:
Copy code
Cannot access class 'kotlinx.coroutines.channels.ReceiveChannel'. Check your module classpath for missing or conflicting dependencies
in the same module when using websockets and channels.
s
Did you include
io.ktor:ktor-serialization-kotlinx-json
as a dependency?
r
Yes
The project is building from gradle and is working fine with new Ktor. The errors are only in IntelliJ.
s
Oh, in that case you might want to try refreshing Gradle inside IntelliJ
cmd+shift+a
->
Refresh Gradle Dependencies
. That triggers IntelliJ to rescan and index the dependencies again, so it might correctly resolve the code after that.
r
Unfortunately it didn't help
s
Strange, this is working for me on Ktor 2.0 with KotlinX Serialization for server.
I have an
api
dependency on KotlinX Coroutines through Arrow Fx Coroutines though, and KotlinX Serialization Gradle Plugin adds a dependency to KotlinX Seriliaziation Core.
r
I see a lot more other errors in IntelliJ as I check different files in my project. All of them are about serialization/coroutines incompatibility or accessibility and not all are Ktor specific. So I think I have some other general problem with my project and IntelliJ. I'll make some more tests with previous Kotlin and Ktor versions.
a
Please try to invalidate caches in IDE.
r
Tried that already, doesn't help
a
Then I can only suggest removing a Gradle cache by deleting ~/.gradle and ~/.m2 folders.
r
It doesn't seem like a cache problem. I have found a different project with similar error:
I can fix this error by changing one dependency in common module from
api
type to
implementation
type
When I go back to
api
the error is back as well.
It's a Ktor project with
implementation("io.ktor:ktor-server-core:$ktorVersion")
dependecy in
jvmMain
source set, so coroutines version 1.6.0 is on the classpath.
It works fine from gradle as well, just this error in IntelliJ.
adding
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
in common source set dosn't fix the problem but
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
does fix the problem
It's a bit crazy 😉
a
This is most likely it.
r
Thanks. It does look similar.