Hi. We are trying to bump Kotlin to 1.7.10 and kto...
# ktor
e
Hi. We are trying to bump Kotlin to 1.7.10 and ktor to 2.0.3. We have a library LibA where we include ktor like this:
Copy code
val ktorVersion = "2.0.3"
implementation("io.ktor:ktor-client:$ktorVersion")
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-apache:$ktorVersion")
implementation("io.ktor:ktor-client-json:$ktorVersion")
implementation("io.ktor:ktor-client-jackson:$ktorVersion")
implementation("io.ktor:ktor-client-logging-jvm:$ktorVersion")
implementation("io.ktor:ktor-client-auth:$ktorVersion")
implementation("io.ktor:ktor-client-websockets:$ktorVersion")
implementation("io.ktor:ktor-client-okhttp:$ktorVersion")
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
implementation("io.ktor:ktor-serialization-jackson:$ktorVersion")
In another lib, LibB we include this lib.
Copy code
implementation("ourgroup:ourapp:version")
When compiling LibB we get this error:
Cannot access class 'io.ktor.client.statement.HttpResponse'. Check your module classpath for missing or conflicting dependencies
We don't reference anything from ktor directly in LibB
a
Does the LibB depend on Ktor library?
e
It does not. It doesn't directly use ktor either
a
Could you please share a sample project to reproduce this issue?
e
The project is for a customer so I can't share much. I can however try to re-create the setup in two blank-ish projects
Copied the projects and started removing stuff. Found out this (client.use) is the problem:
Copy code
suspend fun save() = client.use {
        <http://it.post|it.post>("")
    }
Is the actual problem here that it is a "="-style function which will in this case return "HttpResponse" to the consumer, forcing it to add a dependency to ktor?
a
So if you make the explicit
HttpResponse
type for the
save
function the problem disappears?
e
No that would be the same. It is the same as doing
suspend fun save() = <http://client.post|client.post>("")
. This will return
HttpResonse
. Since this is returned to LibB, LibB needs to know about that class. I would expect it to know about it though LibA, but it does not. It was probably not intentional to expose
HttpResponse
from LibA in the first place
I'm not sure how good it is, but a quickfix is to say the return type is
Unit
a
You can either expose the
HttpResponse
type to the LibB (
api("io.ktor:ktor-client-core:$ktorVersion")
) or return void from the
save
function as you wrote.
e
Wonder why it worked before, the code hasn't changed (much), at least not this part. Unless it has, I wasn't part of that
And of course, there it is. It used to be
<http://it.post|it.post><Unit>
, but it should be
<http://it.post|it.post>().body<Unit>
now I think. And thus it was never cast to
Unit
Thanks for the help. Sorry for the inconvenience. Funny how I immediately jump to the wrong conclusions. Gradle tells me exactly what and where the problem is, yet I think it's Intellij, then IntelliJ+Gradle, then Gradle, then Kotlin etc..