Package okhttp3.logging does not exist

Viewed 10941

I try to use okhttp3.logging to log my retrofit http request.

I add the dependency in the pom.xml:

<dependency>
  <groupId>com.squareup.okhttp3</groupId>
  <artifactId>okhttp</artifactId>
  <version>3.12.1</version>
</dependency>

Unfortunately I have a problem during the import:

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;

Here is the error when compiling:

ERROR] /Users/martin/dev/adm/usersync/usersync-connectors/usersync-connector-discourse/src/main/java/org/xwiki/contrib/usersync/discourse/internal/DiscourseUserSyncConnector.java:[84,48] package HttpLoggingInterceptor does not exist

What is going wrong?

4 Answers

the versions of the okhttp3 and okhttp3:logging-interceptor dependencies needed to exactly match. So for example:

compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'

Probably you need

<dependency>
    <groupId>com.squareup.okhttp3</groupId>
    <artifactId>logging-interceptor</artifactId>
    <version>3.12.1</version>
</dependency>

This worked for me: in gradle file change the next configuration

java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}
Related