slf4j version conflict while building with Maven

前端 未结 3 1388
我在风中等你
我在风中等你 2020-12-08 22:11

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 u

相关标签:
3条回答
  • 2020-12-08 22:41

    Excluding is quite unnecessary and maybe quite misleading. Instead, explicitly include the slf4j-api with the desired version in your projects pom file. That's it!

    This approach takes advantage of Maven's transitivity rules: the nearest dependency declaration wins.

    0 讨论(0)
  • 2020-12-08 22:42

    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
    

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

    0 讨论(0)
  • 2020-12-08 22:42

    you can exclude the wrong version with something like this:

    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate</artifactId>
      <version>3.2.7.ga</version>
      <exclusions>
        <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    
    0 讨论(0)
提交回复
热议问题