https://kotlinlang.org logo
Title
r

Robert Jaros

04/13/2022, 1:25 PM
After upgrading Ktor to 2.0.0, I see this error in IntelliJ only (no error when building from gradle):
Cannot access class 'kotlinx.serialization.json.Json'. Check your module classpath for missing or conflicting dependencies
when I try to use content negotiation:
install(ContentNegotiation) {
        json(json)
    }
I checked the dependencies but I can't see any obvious conflicts.
I see also this error:
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

simon.vergauwen

04/13/2022, 1:37 PM
Did you include
io.ktor:ktor-serialization-kotlinx-json
as a dependency?
r

Robert Jaros

04/13/2022, 1:38 PM
Yes
The project is building from gradle and is working fine with new Ktor. The errors are only in IntelliJ.
s

simon.vergauwen

04/13/2022, 1:49 PM
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

Robert Jaros

04/13/2022, 1:54 PM
Unfortunately it didn't help
s

simon.vergauwen

04/13/2022, 1:58 PM
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

Robert Jaros

04/13/2022, 2:07 PM
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

Aleksei Tirman [JB]

04/13/2022, 3:12 PM
Please try to invalidate caches in IDE.
r

Robert Jaros

04/13/2022, 3:16 PM
Tried that already, doesn't help
a

Aleksei Tirman [JB]

04/13/2022, 3:17 PM
Then I can only suggest removing a Gradle cache by deleting ~/.gradle and ~/.m2 folders.
r

Robert Jaros

04/13/2022, 3:19 PM
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

Aleksei Tirman [JB]

04/13/2022, 3:28 PM
This is most likely it.
r

Robert Jaros

04/13/2022, 3:31 PM
Thanks. It does look similar.