maven Spring Boot:为什么可传递的启动程序依赖项不升级到给定版本?

cu6pst1q  于 2023-02-03  发布在  Maven
关注(0)|答案(1)|浏览(116)

我的pom.xml看起来(部分)像这样:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.6.8</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <version>2.7.8</version>
    </dependency>
</dependencies>

运行mvn dependency:tree将输出以下内容(摘录):

[INFO]    org.springframework.boot:spring-boot-starter:jar:2.7.8:compile
[INFO]    +- org.springframework.boot:spring-boot:jar:2.6.8:compile

为什么spring-boot:jar不也升级到2. 7. 8呢?那是在starter jar中显式声明的版本...

pvcm50d1

pvcm50d11#

spring-boot-starter-parent包括所有Sping Boot 模块的依赖项管理以及大量的第三方依赖项。作为参考,它们列在Spring Boot的文档中。
当你用一个版本声明一个依赖项时,它会覆盖这个依赖项管理,但是只覆盖这个依赖项,而不覆盖它的任何可传递依赖项,这是Maven的标准行为。
一般来说,你应该避免为依赖项管理所覆盖的依赖项声明版本。这样做会产生一个风险,那就是你最终会得到一个混合的版本。在这种情况下,我建议把spring-boot-starter-parent升级到2.7.8,并且让你所有的org.springframework.boot依赖项都没有版本。

相关问题