maven jar包冲突小记

来源:互联网 发布:淘宝大鼻子俄罗斯代购 编辑:程序博客网 时间:2024/05/17 01:04

本地调试报错:

SLF4J: Class path contains multiple SLF4J bindings.SLF4J: Found binding in [jar:file:/E:/repository/org/slf4j/slf4j-nop/1.6.1/slf4j-nop-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]SLF4J: Found binding in [jar:file:/E:/repository/org/slf4j/slf4j-log4j12/1.7.12/slf4j-log4j12-1.7.12.jar!/org/slf4j/impl/StaticLoggerBinder.class]SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.SLF4J: Actual binding is of type [org.slf4j.helpers.NOPLoggerFactory]

分析过程(先后执行了):

        mvn dependency:list
        mvn dependency:tree -Dverbose -Dincludes=org.slf4j

执行后输出为:

[INFO] +- b:c:jar:2.0.0-SNAPSHOT:compile[INFO] |  +- org.slf4j:slf4j-api:jar:1.7.12:compile[INFO] |  \- com.google.code:fqueue:jar:0.0.2-release:compile[INFO] |     +- commons-lang:commons-lang:jar:2.5:compile[INFO] |     +- commons-logging:commons-logging:jar:1.1.1:compile[INFO] |     +- org.slf4j:slf4j-nop:jar:1.6.1:compile[INFO] |     \- org.jboss.netty:netty:jar:3.2.4.Final:compile

[INFO] +- b:d:jar:2.0.0-SNAPSHOT:compile[INFO] |  +- org.slf4j:slf4j-log4j12:jar:1.7.12:runtime[INFO] |  +- log4j:log4j:jar:1.2.16:compile[INFO] |  \- commons-codec:commons-codec:jar:1.4:compile


就是因为a包依赖了b.c和b.d,这两者中的slf4j-nop和slf4j-log4j12冲突了。


解决办法,通过在dependency中采用exclusions来选择性的排除依赖就ok了

                <dependency><groupId>b</groupId><artifactId>c</artifactId><version>2.0.0-SNAPSHOT</version>      <exclusions>        <exclusion>  <!-- declare the exclusion here -->  <groupId>org.slf4j</groupId>  <artifactId>slf4j-nop</artifactId>                  </exclusion>      </exclusions></dependency>


0 0
原创粉丝点击