10

I use java 17 and okhttp-4.9.3. The call is:

OkHttpClient httpClient = new OkHttpClient.Builder().build();

Running the program, i get the exception:

Exception in thread "ReadStationsThread" java.lang.NoClassDefFoundError: okio/Buffer
at [email protected]/okhttp3.ResponseBody$Companion.create(ResponseBody.kt:248)
at [email protected]/okhttp3.ResponseBody$Companion.create$default(ResponseBody.kt:247)
at [email protected]/okhttp3.internal.Util.\<clinit\>(Util.kt:65)

The program can be build without error. I use gradle with these dependencies:

implementation ':okhttp-4.9.3'
implementation ':okio-3.3.0'
implementation ':okio-jvm-3.3.0'
implementation ':kotlin-stdlib-1.8.21'

in the module-info.java is these:

requires okhttp3; 
requires okio; 
requires kotlin.stdlib;

running the program, calls the exception. When i remove the mdule-info.java file, also running the program without modules, it works without problems. Anny idea what the module-info misses?

0

2 Answers 2

5

What worked for me was this version combination:

  • okio-3.5.0
  • okio-jvm-3.5.0
  • okhttp-4.11.0
  • kotlin-stdlib-1.6.20
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for this. I was missing the okio-jvm.
0

Not sure it'll answer your question but found this issue in okhttp repository discussing that okio and related dependencies does not support Java 9 Platform Module System (aka JPMS).

Also see that other issue which is related to the first one.

Moreover, when you look at okio-3.3.0.jar's MANIFEST.MF file, you'll find that there's no Automatic-Module-Name directive (which is Automatic-Module-Name: okio in okio-jvm-3.3.0.jar). Since the Builder class is located in the okio's jar, that would explain why it can't resolve it with current configuration.

Knowing that, is module support a true need in your project since it works without it ?

2 Comments

is module support a true need: yes, i added it to all progs.
Since requires okio; loads the okio-jvm declared module, I'm pretty sure the problem is that the okio library doesn't get his classes loaded since both shared the same package. Did you try upgrading to latest version of okhttp / okio / okio-jvm / kotlin-stdlib ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.