在其他项目中引入依赖项会导致Maven降级okhttp3版本

时间:2020-06-21 11:45:04

标签: java maven

我将我的Maven项目部署到Maven专用服务器。在其他项目中引入依赖项之后,okhttp3的版本从4.7.2更改为3.14.9

[已部署项目的Maven依赖项:mdm-auth-spring-boot-starter] [1] [1]:https://i.stack.imgur.com/JQJe6.png

[另一个项目引入了mdm-auth-spring-boot-starter] [2] [2]:https://i.stack.imgur.com/YVFnI.png

为什么okhttp3的版本已更改?我的系统是Win 10,JDK版本1.8.181,maven版本3.6.3

重新安装系统JDK和maven无法解决此问题。

2 个答案:

答案 0 :(得分:3)

您扩展的spring-boot-starter-parent:2.3.1-RELEASE通过spring-boot-dependenciescom.squareup.okhttp3:okhttp的版本管理为3.14.9:

<okhttp3.version>3.14.9</okhttp3.version>
...
  <dependencyManagement>
    <dependencies>
...
      <dependency>
        <groupId>com.squareup.okhttp3</groupId>
        <artifactId>okhttp</artifactId>
        <version>${okhttp3.version}</version>
      </dependency>
...
    </dependencies>
  </dependencyManagement>

这记录在dependency management下:

每个版本的Spring Boot都提供了它支持的精选依赖性列表。实际上,您不需要在构建配置中为所有这些依赖项提供版本,因为Spring Boot会为您管理该版本。

您需要接受该版本并使用该版本,或者在项目中为要构建的okhttp3.version版本设置okhtttp属性。

答案 1 :(得分:0)

问题可能出在传递依赖项中(某些其他依赖项对okhttp3 3.14.9有依赖关系,它可能会覆盖4.7.2) 您可以尝试执行mvn dependency:tree -Dverbose=true https://maven.apache.org/plugins/maven-dependency-plugin/examples/resolving-conflicts-using-the-dependency-tree.html 并找到您拥有的okhttp3版本,并查看哪个其他依赖项带来了3.14.9版本。