解决JAR包冲突的终极方法-如何找出冲突jar包依赖关系?

JAR包冲突是JAR开发过程中常遇到的问题,近期一个项目过程中,出现了如下的冲突:

org/slf4j/slf4j-log4j12/1.7.25/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]与

ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]冲突。

网上方法大多数是要仔细排查依赖关系,并将多余依赖exclusion,但问题是由于系统依赖jar较多,一一排查,费时费力。

下面给大家提供一种解决办法:

1、程序正常编译后,断开电脑网络。通过工具找出本地maven冲突的jar包,并将其删除,然后重新执行编译、打包动作,这样编译器会提示依赖jar找不到,并提供完整依赖关系,如下图所示

[ERROR] Failed to execute goal on project *****.*****:

Could not resolve dependencies for project ********:jar:1.0:

Failed to collect dependencies at com.hundsun.jrescloud:jrescloud-starter-rpc-def:jar:2.0.17 ->

com.hundsun.jrescloud:jrescloud-rpc-def:jar:2.0.17 ->

com.hundsun.jrescloud:jrescloud-rpc-t2:jar:2.0.17 ->

com.hundsun.jrescloud:jrescloud-rpc-api:jar:2.0.17 ->

com.hundsun.jrescloud:jrescloud-common:jar:2.0.17 ->

org.springframework.boot:spring-boot-starter-aop:jar:1.5.16.RELEASE ->

org.springframework.boot:spring-boot-starter:jar:1.5.16.RELEASE ->

org.springframework.boot:spring-boot-starter-logging:jar:1.5.16.RELEASE ->

ch.qos.logback:logback-classic:jar:1.1.11:

Failed to read artifact descriptor for ch.qos.logback:logback-classic:jar:1.1.11:

Could not transfer artifact ch.qos.logback:logback-classic:pom:1.1.11 from/to *****: Unknown host repos.hundsun.com -> [Help 1]

 

可以知道,冲突包通过com.hundsun.jrescloud:jrescloud-starter-rpc-def初始依赖,在maven引入该包处,增加exclusion处理

<dependency>
    <groupId>com.hundsun.jrescloud</groupId>
    <artifactId>jrescloud-starter-rpc-def</artifactId>
    <!--排除-->
    <exclusions>
        <exclusion>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
        </exclusion>
    </exclusions>
</dependency>

如果还有冲突,继续按此方法排查。一直到编译通过,然后开启网络,即可。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值