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

Spring Cloud Starter依赖是否经过精心筛选?依赖收敛异常咨询

Spring Cloud Starter依赖收敛冲突问题解答

问题场景

在测试项目中引入spring-cloud-starter-netflix-eureka-client:4.0.3时,Maven的dependencyConvergence规则校验失败,报错信息如下:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:3.3.0:enforce (enforce-dependencyConvergence) on project prueba-springboot:
[ERROR] Rule 0: org.apache.maven.enforcer.rules.dependency.DependencyConvergence failed with message:
[ERROR] Failed while enforcing releasability.
[ERROR]
[ERROR] Dependency convergence error for com.netflix.servo:servo-core:jar:0.5.3 paths to dependency are:
[ERROR] +-consejo.prueba:prueba-springboot:jar:0.0.1-SNAPSHOT
[ERROR]   +-org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:jar:4.0.3:compile
[ERROR]     +-com.netflix.eureka:eureka-client:jar:2.0.1:compile
[ERROR]       +-com.netflix.netflix-commons:netflix-eventbus:jar:0.3.0:compile
[ERROR]         +-com.netflix.servo:servo-core:jar:0.5.3:runtime
[ERROR] and
[ERROR] +-consejo.prueba:prueba-springboot:jar:0.0.1-SNAPSHOT
[ERROR]   +-org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:jar:4.0.3:compile
[ERROR]     +-com.netflix.eureka:eureka-client:jar:2.0.1:compile
[ERROR]       +-com.netflix.servo:servo-core:jar:0.12.21:compile

问题解答

1. Spring Cloud Starter的依赖管理逻辑

Spring Cloud Starter和Spring Boot一样,会通过对应的BOM(物料清单)维护一套经过兼容性测试的依赖版本集合,确保同版本Spring Cloud下的各个组件能稳定协作。官方会对starter包含的依赖做筛选和兼容性验证。

2. 本次版本冲突的原因

这次的冲突不属于Spring Cloud Starter的bug,而是eureka-client:2.0.1自身的依赖树存在问题:它既直接依赖了servo-core:0.12.21(compile范围),又通过netflix-eventbus:0.3.0间接引入了旧版本的servo-core:0.5.3(runtime范围)。这种组件内部的嵌套依赖冲突,会触发Maven的dependencyConvergence校验。

3. 可行的解决办法

  • 显式指定依赖版本:在项目的pom.xml中直接声明servo-core的版本,优先选用Spring Cloud BOM中兼容的高版本(比如0.12.21),强制Maven统一使用该版本:
<dependency>
    <groupId>com.netflix.servo</groupId>
    <artifactId>servo-core</artifactId>
    <version>0.12.21</version>
</dependency>
  • 调整校验规则:如果项目对依赖收敛的要求不是必须严格执行,可以修改maven-enforcer-plugin的配置,排除servo-core的收敛检查:
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <version>3.3.0</version>
    <executions>
        <execution>
            <id>enforce-dependencyConvergence</id>
            <goals>
                <goal>enforce</goal>
            </goals>
            <configuration>
                <rules>
                    <DependencyConvergence>
                        <excludes>
                            <exclude>com.netflix.servo:servo-core</exclude>
                        </excludes>
                    </DependencyConvergence>
                </rules>
            </configuration>
        </execution>
    </executions>
</plugin>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 11:13:13