添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
https://kotlinlang.org logo
# http4k
Title
# http4k
r

Razvan

06/20/2021, 1:01 PM
Hi, got an issue that I can’t figure out. I made a lib based on http4k that exposes a method that calls a url using OkHttp client. When I use it from a http4k client app I have no problem, but I also tried to use it from a SpringBoot (kotlin) project and I get this error:
Copy code
Companion
java.lang.NoSuchFieldError: Companion
	at org.http4k.client.OkHttpKt.requestBody(OkHttp.kt:75)
	at org.http4k.client.OkHttpKt.asOkHttp(OkHttp.kt:68)
	at org.http4k.client.OkHttpKt.access$asOkHttp(OkHttp.kt:1)
	at org.http4k.client.OkHttp$invoke$1.invoke(OkHttp.kt:38)
	at org.http4k.client.OkHttp$invoke$1.invoke(OkHttp.kt:35)
It’s the basic client, nothing fancy
OkHtttp()
if I replace that with JavaHttpClient() or ApacheClient() all works. Does that ring a bel or should try to make test projects to show it ? The error line is the if line in this function
Copy code
private fun Request.requestBody() =
    if (permitsRequestBody(method.toString())) body.payload.array().toRequestBody()
    else null
So comparing the dependecies I see that in the Spring boot version the
http4k-client-okhttp
adds okhttp 3.14.9 instead of 4.9.1 in the http4k version.
d

dave

06/20/2021, 1:22 PM
Yep. Try to force the version maybe?
r

Razvan

06/20/2021, 1:38 PM
If in the lib i set the okhttp the dependency as:
Copy code
api("com.squareup.okhttp3:okhttp:4.9.1")
is not ok. If I do it in the SpringBoot app (as implement) is OK. but I shouldn’t have to care about that as in my spring boot app I’m not using okhttp in this client app…
Gradle dependency report does not help the only place where okhttp appears is in the http4k-client but yet the dependency is marked as omitted as (
(*) - dependencies omitted (listed previously)
) but there’s nowhere else…
Copy code
|    +--- org.http4k:http4k-client-okhttp:4.9.8.0