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

多模块Maven项目中Liquibase依赖版本异常求助

问题原因
  1. Maven依赖管理机制限制:父项目A的dependencyManagement仅做版本约定,不会自动覆盖所有传递依赖。只有当子模块(B/C)显式声明liquibase-core依赖且不指定版本时,才会继承父项目约定的4.18.0版本。如果模块B是通过其他依赖间接引入Liquibase 4.9.1,且B未显式声明liquibase-core,Maven会默认采用传递过来的旧版本。
  2. 依赖优先级规则:多版本传递依赖场景下,Maven默认优先选择路径最短的版本;若路径长度一致,则选择声明顺序靠前的版本。你的场景中,4.9.1版本的传递依赖路径优先级高于父项目约定的版本。
解决方案

方案1:模块B显式声明Liquibase依赖

在模块B的pom.xml中添加liquibase-core依赖,不指定版本,让它继承父项目的4.18.0版本,直接覆盖传递过来的旧版本:

<dependencies>
    <!-- 其他业务依赖 -->
    <dependency>
        <groupId>org.liquibase</groupId>
        <artifactId>liquibase-core</artifactId>
    </dependency>
</dependencies>

方案2:排除传递依赖中的旧版Liquibase

先通过Maven命令定位引入4.9.1版本的依赖源:

mvn dependency:tree -Dincludes=org.liquibase:liquibase-core

找到对应依赖后,在模块B的pom.xml中排除该依赖携带的旧版Liquibase,再显式声明继承父项目版本的依赖:

<dependency>
    <groupId>问题依赖的groupId</groupId>
    <artifactId>问题依赖的artifactId</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-core</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<!-- 显式声明使用父项目约定的版本 -->
<dependency>
    <groupId>org.liquibase</groupId>
    <artifactId>liquibase-core</artifactId>
</dependency>

方案3:项目C中强制指定版本

如果前两种方案无效,可在项目C的pom.xml中先排除模块B传递过来的旧版Liquibase,再显式声明依赖:

<dependency>
    <groupId>模块B的groupId</groupId>
    <artifactId>模块B的artifactId</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-core</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>org.liquibase</groupId>
    <artifactId>liquibase-core</artifactId>
</dependency>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 01:45:24