maven - 错误 SLF4J : Class path contains multiple SLF4J bindings jenkins cobertura maven

标签 maven jenkins pom.xml slf4j cobertura

我已经在第三天遇到了这个错误,我无法解决。有些东西我无法掌握,无论我做什么,错误仍然存​​在。

我正在阅读一本名为“Jenkins 权威指南”(http://www.wakaleo.com/books/jenkins-the-definitive-guide)的书,但我被困在第二章。基本上是一个如何将 Jenkins 与 Javadoc、JUnit 和 Cobertura 插件一起用于 Jenkins 的示例。一切正常,直到我到达 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-simple 的 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-classic 没有明确的依赖关系,因此我不知道正在使用什么依赖关系。我尝试使用 jenkins 的依赖插件,我得到了这个结果:
[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-classic(顺便说一句,我不确定哪些值对于 logback-classic 是正确的)。
我试图删除 slf4j 依赖项,但我的错误消失了,但我没有收到任何 cobertura 报告。我试图排除 logback-classic
    <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>

并且错误仍然存​​在。
我不知道该怎么办了,请帮助!

最佳答案

好消息是即使 SLF4J 报错,它实际上是在警告你 SLF4J 将绑定(bind)到 ch.qos.logback.classic.util.ContextSelectorStaticBinder因为类路径上有两个可用的绑定(bind)。 SLF4J 将选择类路径中第一个可用的。尽管使用 logback 进行日志记录,您的应用程序应该可以继续正常工作。

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

关于maven - 错误 SLF4J : Class path contains multiple SLF4J bindings jenkins cobertura maven,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30495605/

相关文章:

java - 从顶级模块中排除 Maven 子模块依赖项

java - WSDL URL 的 Maven 过滤

jenkins - 如何创建不同的,已解锁并带有预加载插件的Jenkins2图像?

java - 从 pom 加载 hello_stateless_ejb 项目

windows-7 - 无法使用 tomcat-maven-plugin 从另一台计算机(windows 7)部署到 tomcat 7(在 windows 7 计算机上)

spring - 找不到 pom.xml 文件 - Heroku

Jenkins Pipeline 发布 html 报告

python - Jenkins:将我的 Python 模块放在 PYTHONPATH 上

java.lang.NoClassDefFoundError : Failed to link net/glxn/qrgen/javase/QRCode

ruby - 为什么 Buildr 失败了?