我试图在我的Spring引导项目中使用okhttp3.mockwebserver,我发现包含了okhttp3 3:mockwebserver:jar:3.14.9,而不是4.9.1。
我创建了一些小的“模拟”项目来复制我在我的产品中的问题。
这个项目在这里,https://github.com/mkarasik/okhttp-test
它包含两个文件夹:
库
这是一个简单的库,包括mockwebserver作为依赖项。
pom.xml依赖
<dependencies>
...
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<version>4.9.1</version>
<exclusions>
<exclusion>
<artifactId>junit</artifactId>
<groupId>junit</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
Maven依赖树
\- com.squareup.okhttp3:mockwebserver:jar:4.9.1:compile
+- com.squareup.okhttp3:okhttp:jar:3.14.9:compile
这已经是错误的了。Mockwebserver包含4.9.1 okhttp伪影,但3.14.9显示在树中。
项目
简单的Spring应用程序,包括lib项目
<dependency>
<groupId>com.example</groupId>
<artifactId>lib</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>test</scope>
</dependency>
Maven依赖树
\- com.example:lib:jar:0.0.1-SNAPSHOT:test
\- com.squareup.okhttp3:mockwebserver:jar:3.14.9:test
\- com.squareup.okhttp3:okhttp:jar:3.14.9:test
\- com.squareup.okio:okio:jar:1.17.2:test
同样的问题也在这里。包含了okhttp3 3:mockwebserver:jar:3.14.9,而不是在我的lib pom.xml中指定的4.9.1。
在我的xml配置中有遗漏什么吗?
发布于 2022-04-07 19:12:42
在Introducing dependencies in other projects causes Maven to downgrade okhttp3 version中有描述
<properties>
<okhttp3.version>4.9.1</okhttp3.version>
</properties>
解决问题
发布于 2022-04-11 07:27:52
OkHttp提供了一个Maven BOM,您可以使用它来确保一致的版本
https://github.com/square/okhttp#releases
还提供了一份材料清单(BOM),以帮助您保持OkHttp工件的最新更新,并确保版本兼容性。
这个例子是gradle,但它最初是maven的一个特性。
https://docs.gradle.org/6.2/userguide/platforms.html#sub:bom_import
dependencies {
// define a BOM and its version
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.9.3"))
// define any required OkHttp artifacts without version
implementation("com.squareup.okhttp3:okhttp")
implementation("com.squareup.okhttp3:logging-interceptor")
}
https://stackoverflow.com/questions/71784140
复制相似问题