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