You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Maven多级继承场景下dependencyManagement依赖版本不生效问题求助

问题根因

你遇到的报错是Maven的dependencyManagement覆盖规则导致的:

  • spring-boot-starter-parent本身已经在内置的dependencyManagement中定义了所有Spring Boot官方组件的版本,你自定义的parent项目继承它之后,在自己的dependencyManagement中声明spring-boot-starter-webflux时不需要写版本,就能自动继承spring-boot-starter-parent提供的版本号。
  • 但你在mid项目的dependencyManagement中重复声明了同groupId、同artifactId的spring-boot-starter-webflux依赖,且没有指定版本。根据Maven规则,子项目的dependencyManagement声明优先级高于父项目,同groupId、artifactId的条目会直接覆盖父级配置,此时Maven会认为spring-boot-starter-webflux的管理版本为空,因此子项目child引用该依赖时就会报版本未找到的错误。
  • 你给parent的对应依赖加版本也不生效,正是因为mid层的无版本条目已经覆盖了上层配置,Maven不会再往上溯源找版本。

解决方案

你可以二选一:

  • 直接删除mid项目dependencyManagement中重复的spring-boot-starter-webflux声明。mid继承自parent,已经可以直接复用parent层的依赖版本管理配置,不需要重复声明,child继承mid后也能正常获取到版本号。
  • 如果你确实需要在mid层的dependencyManagement中保留该依赖声明(比如后续要统一修改版本),可以显式指定版本为${spring-boot.version},该属性是spring-boot-starter-parent内置的版本属性,不需要你手动写死版本号。

内容的提问来源于stack exchange,提问作者SoT

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.20 18:06:02