SLF4J导致多个类名与sbt-assembly冲突

时间:2016-03-25 20:30:02

标签: sbt sbt-assembly

我用sbt-assembly(下面)得到了着名的SLF4J类名碰撞错误。 SLF4J docs do say在这方面是病态的,在某种程度上保持一点模糊。无论如何,这发生在具有大量依赖性的项目中,并且仍然不清楚应该如何计算哪些类可以被丢弃以避免冲突而不会在运行时崩溃。

[error] (project-name/*:assembly) deduplicate: different file contents found in the following:
[error] .ivy2/cache/commons-logging/commons-logging/jars/commons-logging-1.2.jar:org/apache/commons/logging/Log.class
[error] .ivy2/cache/org.slf4j/jcl-over-slf4j/jars/jcl-over-slf4j-1.7.12.jar:org/apache/commons/logging/Log.class
[error] deduplicate: different file contents found in the following:
[error] .ivy2/cache/commons-logging/commons-logging/jars/commons-logging-1.2.jar:org/apache/commons/logging/LogConfigurationException.class
[error] .ivy2/cache/org.slf4j/jcl-over-slf4j/jars/jcl-over-slf4j-1.7.12.jar:org/apache/commons/logging/LogConfigurationException.class
[error] deduplicate: different file contents found in the following:
[error] .ivy2/cache/commons-logging/commons-logging/jars/commons-logging-1.2.jar:org/apache/commons/logging/LogFactory.class
[error] .ivy2/cache/org.slf4j/jcl-over-slf4j/jars/jcl-over-slf4j-1.7.12.jar:org/apache/commons/logging/LogFactory.class
[error] deduplicate: different file contents found in the following:
[error] .ivy2/cache/commons-logging/commons-logging/jars/commons-logging-1.2.jar:org/apache/commons/logging/impl/NoOpLog.class
[error] .ivy2/cache/org.slf4j/jcl-over-slf4j/jars/jcl-over-slf4j-1.7.12.jar:org/apache/commons/logging/impl/NoOpLog.class
[error] deduplicate: different file contents found in the following:
[error] .ivy2/cache/commons-logging/commons-logging/jars/commons-logging-1.2.jar:org/apache/commons/logging/impl/SimpleLog$1.class
[error] .ivy2/cache/org.slf4j/jcl-over-slf4j/jars/jcl-over-slf4j-1.7.12.jar:org/apache/commons/logging/impl/SimpleLog$1.class
[error] deduplicate: different file contents found in the following:
[error] .ivy2/cache/commons-logging/commons-logging/jars/commons-logging-1.2.jar:org/apache/commons/logging/impl/SimpleLog.class
[error] .ivy2/cache/org.slf4j/jcl-over-slf4j/jars/jcl-over-slf4j-1.7.12.jar:org/apache/commons/logging/impl/SimpleLog.class
[error] deduplicate: different file contents found in the following:
[error] .ivy2/cache/ch.qos.logback/logback-classic/jars/logback-classic-1.1.3.jar:org/slf4j/impl/StaticLoggerBinder.class
[error] .ivy2/cache/org.slf4j/slf4j-nop/jars/slf4j-nop-1.6.4.jar:org/slf4j/impl/StaticLoggerBinder.class
[error] deduplicate: different file contents found in the following:
[error] .ivy2/cache/ch.qos.logback/logback-classic/jars/logback-classic-1.1.3.jar:org/slf4j/impl/StaticMDCBinder.class
[error] .ivy2/cache/org.slf4j/slf4j-nop/jars/slf4j-nop-1.6.4.jar:org/slf4j/impl/StaticMDCBinder.class
[error] deduplicate: different file contents found in the following:
[error] .ivy2/cache/ch.qos.logback/logback-classic/jars/logback-classic-1.1.3.jar:org/slf4j/impl/StaticMarkerBinder.class
[error] .ivy2/cache/org.slf4j/slf4j-nop/jars/slf4j-nop-1.6.4.jar:org/slf4j/impl/StaticMarkerBinder.class

解决这个可怕混乱的方法可能是什么?我真的很想知道,为什么这是包装中的问题(sbt assembly),而不是像sbt run那样在sbt中运行项目?

非常感谢!

1 个答案:

答案 0 :(得分:3)

您是否已阅读README.md中的Bridging legacy APIs的实际链接?:

  

从Jakarta Commons Logging(JCL)逐步迁移到SLF4J

     

JCL-过slf4j.jar

     

为了便于从JCL迁移到SLF4J,SLF4J发行版包括jar文件jcl-over-slf4j.jar。此jar文件旨在作为JCL 1.1.1版的替代品。它实现了JCL的公共API,但在下面使用了SLF4J,因此名称为“JCL over SLF4J。”

     

我们通过SLF4J实现的JCL将允许您逐步迁移到SLF4J,特别是如果您的软件所依赖的某些库在可预见的将来继续使用JCL。

jcl-over-slf4j.jar “旨在作为JCL版本1.1.1的替代品。”因此预期目的是删除Commons Logging。

  

解决这个可怕混乱的方法可能是什么?

运行show update,找出commons-logging的来源,并将其从依赖项中排除。

  

我真的很想知道,为什么这是包装(sbt assembly)中的问题,而不是像sbt run中那样在sbt中运行项目?

这是一个真正的病态类路径。在日志记录方面,您的代码的某些部分可能会做出与预期完全不同的事情。如果你想去俄罗斯轮盘赌路线,总会有MergeStrategy.first