首页 > 解决方案 > maven:替换传递依赖版本

问题描述

这里有一个mvn dependency:tree片段:

...
+- org.springframework.boot:spring-boot-starter-actuator:jar:2.1.12.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-actuator-autoconfigure:jar:2.1.12.RELEASE:compile
[INFO] |  |  \- org.springframework.boot:spring-boot-actuator:jar:2.1.12.RELEASE:compile
[INFO] |  \- io.micrometer:micrometer-core:jar:1.1.9:compile
...

如您所见,我的项目使用的是 1.1.9 版本的io.micrometer:micrometer-core.

我想使用这个库的最新版本。

这个版本是由于:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.12.RELEASE</version>
</parent>

我无法更改此版本。

有没有办法只io.micrometer:micrometer-core:1.1.19被另一个最近的覆盖?

标签: spring-bootmaven

解决方案


覆盖传递依赖的最佳方法是将版本放入<dependencyManagement>.

只需添加一个条目

<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-core</artifactId>
    <version>...</version>
</dependency>

<dependencyManagement>您的 POM 部分。这将覆盖传递依赖,但不会影响直接依赖。此外,如果这个 jar 将来可能不再是传递依赖项,它将被忽略。


推荐阅读