2015-05-28 95 views
2

我在第三天就出现这个错误,我无法解决。有些东西我无法理解,无论我做什么,错误依然存在。错误SLF4J:类路径包含多个SLF4J绑定jenkins cobertura maven

我正在读一本名为“詹金斯一本权威指南”(http://www.wakaleo.com/books/jenkins-the-definitive-guide)的书,我被困在第二章。基本上是一个如何使用詹金斯Javadoc,JUnit和Cobertura插件的例子。一切正常,直到我得到的Cobertura插件的一部分,在那里我得到一个错误:

[ERROR] SLF4J: Class path contains multiple SLF4J bindings. 
SLF4J: Found binding in [jar:file:/C:/Windows/System32/config/systemprofile/.m2/repository/ch/qos/logback/logback-classic/1.0.13/logback-classic-1.0.13.jar!/org/slf4j/impl/StaticLoggerBinder.class] 
SLF4J: Found binding in [jar:file:/C:/Windows/System32/config/systemprofile/.m2/repository/org/slf4j/slf4j-simple/1.6.1/slf4j-simple-1.6.1.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 [ch.qos.logback.classic.util.ContextSelectorStaticBinder] 

我所看到的其他问题,像我的,我得到的结论是,我既可以包括邻排除在我的POM的依赖。 xml文件/ s(这个例子在这个阶段只使用pom文件)。有SLF4J-简单我的pom.xml文件看起来是这样的:

<project> 
...... 
    <dependencies> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-simple</artifactId> 
      <version>1.6.1</version> 
     </dependency> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-api</artifactId> 
      <version>1.6.1</version> 
     </dependency> 
    </dependencies> 
</project> 

并没有显式依赖于的logback经典所以我没有使用什么样的依赖性知道做。我试图使用依赖插件詹金斯,我得到了这样的结果:

[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ gameoflife-web --- 
[INFO] com.wakaleo.gameoflife:gameoflife-web:war:1.0-SNAPSHOT 
[INFO] +- com.wakaleo.gameoflife:gameoflife-core:jar:1.0-SNAPSHOT:compile 
[INFO] +- org.springframework:spring-webmvc:jar:3.0.2.RELEASE:compile 
[INFO] | +- org.springframework:spring-asm:jar:3.0.2.RELEASE:compile 
[INFO] | +- org.springframework:spring-beans:jar:3.0.2.RELEASE:compile 
[INFO] | +- org.springframework:spring-context:jar:3.0.2.RELEASE:compile 
[INFO] | | \- org.springframework:spring-aop:jar:3.0.2.RELEASE:compile 
[INFO] | +- org.springframework:spring-context-support:jar:3.0.2.RELEASE:compile 
[INFO] | \- org.springframework:spring-expression:jar:3.0.2.RELEASE:compile 
[INFO] +- org.springframework:spring-core:jar:3.0.2.RELEASE:compile 
[INFO] | \- commons-logging:commons-logging:jar:1.1.1:compile 
[INFO] +- org.springframework:spring-web:jar:3.0.2.RELEASE:compile 
[INFO] | \- aopalliance:aopalliance:jar:1.0:compile 
[INFO] +- javax.servlet:jstl:jar:1.2:compile 
[INFO] +- javax.servlet:servlet-api:jar:2.5:provided 
[INFO] +- org.mockito:mockito-all:jar:1.8.5:test 
[INFO] +- org.easytesting:fest-assert:jar:1.4:compile 
[INFO] | \- org.easytesting:fest-util:jar:1.1.6:compile 
[INFO] +- org.slf4j:slf4j-simple:jar:1.6.1:compile 
[INFO] +- org.slf4j:slf4j-api:jar:1.6.1:compile 
[INFO] +- junit:junit:jar:4.11:test 
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test 
[INFO] \- org.hamcrest:hamcrest-all:jar:1.1:test 

也许我是盲人,但我仍然无法看到谁使用的logback 经典(顺便说一下,我不知道什么值是正确的对于logback-classic)。 我试图删除slf4j依赖关系的和我错误消失了,但我没有得到任何cobertura报告。我试图排除的logback经典

<dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-simple</artifactId> 
     <version>1.6.1</version> 
     <exclusions> 
      <exclusion> 
       <groupId>ch.qos.logback</groupId> 
       <artifactId>logback-classic</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 
    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-api</artifactId> 
     <version>1.6.1</version> 
     <exclusions> 
      <exclusion> 
       <groupId>ch.qos.logback</groupId> 
       <artifactId>logback-classic</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 

和错误仍然存​​在。 我不知道该怎么办,请帮忙!

+0

可能重复的[在Maven项目中解决多个SLF4J绑定](http://stackoverflow.com/questions/11758676/resolve-multiple-slf4j-bindings-in-maven-project) –

+0

是的,它可能是一个可能的重复,当我知道肯定,我会更新它。 –

回答

0

您试图从slf依赖项本身中排除logback-classic。问题在于,如上所述here,您在类路径中使用了多个绑定。实际的方法是在logback-classic中保留排除,在使用它的依赖中,而不是在slf4j依赖中。不幸的是,我不确定你的哪个罐子,有引用slf4j的问题。一种解决方法是,使用Ctrl + Sft + T在不同的jar中查看StaticLoggerBinder类的存在,并将logback-classic排除在其中。其他的解决方法是,你可以尝试保持排除,作为反复试验。这些只是解决方法,但概念是相同的。我们需要在你的类路径中找到其他依赖logback-classic

+0

当你说“使用Ctrl + Sft + T”你究竟是什么意思?我应该在哪里使用它?在我的编辑器中?我不知道这个关键捷径。 –

+0

它用于搜索包括罐子在内的工作空间中的资源发生。 – Ramzy

+0

我刚试过Ctrl + Sft + T,它* StatigLoggerBinder *没有出现。我遇到的困难之一是代码不是我的,来自书中,我添加了所有丢失的包(至少我能找到的所有包),并且我没有运气。我想我应该尝试和错误的方法。还有其他方法可以找出重新排列?非常感谢。 –

0

好消息是,即使SLF4J报告了一个错误,它实际上是警告你SLF4J将被绑定到ch.qos.logback.classic.util.ContextSelectorStaticBinder,因为有两个绑定可用在班级路径上。 SLF4J将选择课程路径中的第一个。虽然使用logback进行日志记录,但您的应用程序仍应继续正常工作。

我不能告诉你为什么logback-classic.jar在类路径上,但我建议你研究类路径中提到的“系统配置文件”。

+0

那么,我没有得到cobertura报告,这个错误是唯一明显的原因。我将调查“系统配置文件”并回顾我的结论。非常感谢。 –