使用Maven构建时slf4j版本冲突 [英] slf4j version conflict while building with Maven

查看:1432
本文介绍了使用Maven构建时slf4j版本冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到我的一个项目使用slf4j 1.5.8而Hibernate使用slf4j 1.6。在使用Maven构建时,它会下载两个jar,但我想使用的是1.5.8的类文件。所以,当我运行程序时,我得到以下错误:

I realised that one of my projects uses slf4j 1.5.8 and Hibernate uses slf4j 1.6. While building with Maven it downloads both jars but I guess the class files of 1.5.8 are used. So, when I run the program i get following error:

SLF4J: The requested version 1.5.8 by your slf4j binding is not compatible with [1.6]

pom.xml 我已经

<dependencyManagement>    
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.1</version>
    </dependency>
</dependencyManagement>

1.5.8是依赖项的一部分,因此它可以单独下载。

The 1.5.8 is part of dependency so it's downloaded on its own.

推荐答案

正如您自己发现的那样,有两个库(Hibernate和其他一些)在两个不同的版本中传递导入SLF4J。不幸的是,旧版本正被maven接收(在这种情况下,有一些规则应该由maven选择依赖关系)。解决方案是在导入旧版本SLF4J的依赖项中添加排除 com.example:foo-bar 例如这里的例子):

As you discovered yourself, there are two libraries (Hibernate and some other) transitively importing SLF4J in two different versions. Unfortunately the older version is being picked up by maven (there are some rules which dependency should be chosen by maven in this situation). The solution is to add the exclusion in the dependency that imports older version of SLF4J (com.example:foo-bar is example here):

<dependency>
  <groupId>com.example</groupId>
  <artifactId>foo-bar</artifactId>
  <version>1.2.3</version>
   <exclusions>
     <exclusion>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
     </exclusion>
   </exclusions>
</dependency>

如果您仍遇到此问题,请发出:

If you still experience this problem, issue:

$ mvn dependency:tree

寻找1.5。 8版本并将其从导入它的所有库中排除。

Look for 1.5.8 version and exclude it from all libraries importing it.

这篇关于使用Maven构建时slf4j版本冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆