软件包okhttp3.logging不存在

时间:2019-01-10 10:38:07

标签: java okhttp3

我尝试使用okhttp3.logging记录我的改造http请求。

我在pom.xml中添加了依赖项:

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

不幸的是,我在导入过程中遇到了问题:

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

这是编译时的错误:

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

出了什么问题?

4 个答案:

答案 0 :(得分:3)

可能您需要

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

答案 1 :(得分:0)

需要完全匹配的okhttp3和okhttp3:logging-interceptor依赖项的版本。例如:

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

答案 2 :(得分:0)

您必须查阅Maven资源库站点

https://mvnrepository.com/artifact/com.squareup.okhttp3/logging-interceptor/3.12.1

<!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/logging-interceptor -->
<dependency>
    <groupId>com.squareup.okhttp3</groupId>
    <artifactId>logging-interceptor</artifactId>
    <version>3.12.1</version>
</dependency>

答案 3 :(得分:0)

这对我有用:在 gradle 文件中更改下一个配置

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