chr*_*tek 22 java dependencies hibernate slf4j maven
我有一个独立使用两个依赖项的项目:BoneCP和Hibernate.但是由于SLF4J及其版本冲突它不起作用,因为BoneCP需要SLF4J 1.5而Hibernate需要SLF4j 1.6.如您所知,不可能在pom.xml中重要两个不同版本的相同依赖项.那么我该怎么办才能解决这个惊人的SLF4J副作用?
我得到的错误是臭名昭着的:
SLF4J: The requested version 1.5.10 by your slf4j binding is not compatible with [1.6]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
Run Code Online (Sandbox Code Playgroud)
我需要添加它,但不允许使用两个不同版本的相同依赖:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.10</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.2</version>
<scope>provided</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
Maven依赖树:
[INFO] [dependency:tree {execution: default-cli}]
[INFO] org.mentawai:menta:war:1.0.5-SNAPSHOT
[INFO] +- javax.servlet.jsp:jsp-api:jar:2.0:provided
[INFO] +- javax.servlet:servlet-api:jar:2.5:provided
[INFO] +- javax.activation:activation:jar:1.1:compile
[INFO] +- javax.mail:mail:jar:1.4:compile
[INFO] +- javax.persistence:persistence-api:jar:1.0:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.5.10:compile
[INFO] | +- org.slf4j:slf4j-api:jar:1.5.10:compile
[INFO] | \- log4j:log4j:jar:1.2.14:compile
[INFO] +- org.hibernate:hibernate-core:jar:3.6.7.Final:compile
[INFO] | +- antlr:antlr:jar:2.7.6:compile
[INFO] | +- commons-collections:commons-collections:jar:3.1:compile
[INFO] | +- dom4j:dom4j:jar:1.6.1:compile
[INFO] | +- org.hibernate:hibernate-commons-annotations:jar:3.2.0.Final:compile
[INFO] | +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
[INFO] | \- javax.transaction:jta:jar:1.1:compile
[INFO] +- javassist:javassist:jar:3.12.1.GA:compile
[INFO] +- junit:junit:jar:4.8.1:test
[INFO] +- c3p0:c3p0:jar:0.9.1.2:compile
[INFO] +- com.h2database:h2:jar:1.2.138:compile
[INFO] +- mysql:mysql-connector-java:jar:5.1.13:compile
[INFO] +- me.soliveirajr:mentawai:jar:2.3.3-SNAPSHOT:compile
[INFO] | +- net.sf.json-lib:json-lib:jar:jdk15:2.3:compile
[INFO] | | +- commons-beanutils:commons-beanutils:jar:1.8.0:compile
[INFO] | | +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] | | \- net.sf.ezmorph:ezmorph:jar:1.0.6:compile
[INFO] | +- org.jdom:jdom:jar:1.1:compile
[INFO] | +- com.thoughtworks.xstream:xstream:jar:1.3.1:compile
[INFO] | | \- xpp3:xpp3_min:jar:1.1.4c:compile
[INFO] | +- org.ajaxtags:ajaxtags:jar:1.2-beta3:compile
[INFO] | | +- javax.servlet:jstl:jar:1.0.6:compile
[INFO] | | +- taglibs:standard:jar:1.0.6:compile
[INFO] | | \- net.htmlparser:jericho-html:jar:2.1:compile
[INFO] | +- jgroups:jgroups-all:jar:2.2.9.1:compile
[INFO] | +- me.soliveirajr:menta-container:jar:0.9.8:compile
[INFO] | +- me.soliveirajr:menta-bean:jar:1.1.1:compile
[INFO] | +- me.soliveirajr:menta-regex:jar:0.9.5:compile
[INFO] | +- org.beanshell:bsh:jar:2.0b4:compile
[INFO] | +- com.jolbox:bonecp:jar:0.7.1.RELEASE:compile
[INFO] | | \- com.google.guava:guava:jar:r08:compile
[INFO] | +- velocity:velocity-dep:jar:1.4:compile
[INFO] | +- commons-fileupload:commons-fileupload:jar:1.2.2:compile
[INFO] | +- commons-io:commons-io:jar:1.3.2:compile
[INFO] | +- net.tanesha.recaptcha4j:recaptcha4j:jar:0.0.7:compile
[INFO] | \- commons-dbcp:commons-dbcp:jar:1.4:compile
[INFO] | \- commons-pool:commons-pool:jar:1.5.4:compile
[INFO] +- commons-lang:commons-lang:jar:2.5:compile
[INFO] \- asm:asm:jar:3.2:compile
Run Code Online (Sandbox Code Playgroud)
Cek*_*eki 30
错误消息" http://www.slf4j.org/codes.html#version_mismatch "中提供的链接指出:
SLF4J绑定指定一个工件,例如slf4j-jdk14.jar或slf4j-log4j12.jar,用于将slf4j绑定到底层日志框架,例如java.util.logging或log4j.混合混合不同版本的slf4j-api.jar和SLF4J绑定可能会导致问题.例如,如果您使用的是slf4j-api-1.6.6.jar,那么您还应该使用slf4j-simple-1.6.6.jar,使用slf4j-simple-1.5.5.jar将无效.
注意从客户端的角度来看,所有版本的slf4j-api都是兼容的.对于任何N和M,使用slf4j-api-N.jar编译的客户端代码与slf4j-api-M.jar完全匹配.您只需要确保绑定的版本与slf4j-api.jar的版本匹配.您不必担心项目中给定依赖项使用的slf4j-api.jar版本.你总是可以使用任何版本的slf4j-api.jar,只要slf4j-api.jar的版本及其绑定匹配,你应该没问题.
鉴于slf4j-api的所有版本都可以从客户端角度进行互换,在不同版本的slf4j-api及其绑定例如slf4j-log4j12被引入的场景中,将它们显式声明为POM中的依赖项,如下所示:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
在这里,我假设您实际上不需要在提供的范围内声明slf4j-api和slf4j-log4j12.
另见依赖机制简介,其中说明:
依赖关系中介 - 确定在遇到工件的多个版本时将使用哪个版本的依赖关系.目前,Maven 2.0仅支持使用" 最接近的定义 ",这意味着它将在依赖树中使用与项目最接近的依赖项版本.您可以通过在项目的POM中明确声明它来保证版本.
小智 5
只需排除1.5.10版本的SLF4J
<dependency>
<groupId>...</groupId>
<artifactId>BoneCP</artifactId>
<version>...</version>
<exclusions>
<exclusion> <!-- declare the exclusion here -->
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.10</version>
</exclusion>
</exclusions>
</dependency>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
45382 次 |
| 最近记录: |