You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Maven配置OkHttp v5?

如何使用Maven配置OkHttp v5?

我完全懂你这种挫败感——OkHttp v5的大版本更新带了一堆破坏性变更,而且官方文档基本都在讲Gradle怎么配,Maven用户确实容易被晾在一边。你遇到的“找不到类”问题,核心原因其实是OkHttp v5的groupId变了!

之前v3、v4版本我们用的groupId是com.squareup.okhttp3,但v5直接把末尾的3去掉了,换成了com.squareup.okhttp。你现在的依赖还是用的旧groupId,Maven拉到的其实不是正确的v5包,自然找不到对应的类。

给你贴一个正确的Maven依赖配置,直接替换你当前的依赖就行:

<dependencies>
    <dependency>
        <groupId>com.squareup.okhttp</groupId>
        <artifactId>okhttp</artifactId>
        <version>5.0.0</version>
    </dependency>
</dependencies>

另外还有两个需要注意的点:

  • 如果你项目里还用到了OkHttp的其他扩展模块(比如日志拦截器、URLConnection适配包这些),它们的groupId也要同步改成com.squareup.okhttp,版本保持和核心库一致。比如日志拦截器的配置是:
    <dependency>
        <groupId>com.squareup.okhttp</groupId>
        <artifactId>okhttp-logging-interceptor</artifactId>
        <version>5.0.0</version>
    </dependency>
    
  • 改完依赖后,建议执行mvn clean install -U强制刷新Maven依赖缓存,避免旧的缓存包干扰。

这样配置完之后,你的项目应该就能正常识别OkHttp v5的所有类了,试试吧!

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.07 10:29:29