scala - 如何让 sbt-assembly 合并正确?

标签 scala sbt scalatra

在我们的 Scala/Scalatra 项目中,我们为插件 sbt-assembly 设置了合并策略:

assemblyMergeStrategy in assembly := {
  case x =>
   val oldStrategy = (assemblyMergeStrategy in assembly).value
   oldStrategy(x)
}

[error] 11 errors were encountered during merge java.lang.RuntimeException: deduplicate: different file contents found in the following: ~/.ivy2/cache/org.scalatra/scalatra_2.11/jars/scalatra_2.11-2.3.1.jar:mime.types ~/.ivy2/cache/com.amazonaws/aws-java-sdk-s3/jars/aws-java-sdk-s3-1.10.1.jar:mime.types

deduplicate: different file contents found in the following:
~/.ivy2/cache/commons-beanutils/commons-beanutils/jars/commons-beanutils-1.8.3.jar:org/apache/commons/collections/ArrayStack.class
~/.ivy2/cache/commons-collections/commons-collections/jars/commons-collections-3.2.1.jar:org/apache/commons/collections/ArrayStack.class
deduplicate: different file contents found in the following:

and the same error for different class names

这里正确的合并逻辑是什么?

版本:

斯卡拉:2.11.7
SBT:0.13.9
sbt 程序集:0.13.0

最佳答案

我不认为,这是“合并策略”的问题,而是您正在使用的更多库及其依赖项。

谁“拉动”了这些依赖关系?您具体使用了哪些库?

限制的一种方法是使用 excludeAll (和类似的)与依赖声明。 (参见 library management in SBT ),例如

excludeAll(
  ExclusionRule("commons-beanutils", "commons-beanutils-core"),
  ExclusionRule("commons-collections", "commons-collections"),
  ExclusionRule("commons-logging", "commons-logging"),
  ExclusionRule("org.slf4j", "slf4j-log4j12"),
  ExclusionRule("org.hamcrest", "hamcrest-core"),
  ExclusionRule("junit", "junit"),
  ExclusionRule("org.jboss.netty", "netty"),
  ExclusionRule("com.esotericsoftware.minlog", "minlog")
  )

关于scala - 如何让 sbt-assembly 合并正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32497280/

相关文章:

java - 带有 Spark 的 NoClassDefFoundError

unit-testing - 如何使用 Scalatra、Specs2、Mockito 重置模拟调用计数器

scala - 如何将 Scala 枚举作为参数传递?

scala - 找不到用于测试的现有数据 Scala Specs2

scala - Scala 中的隐式类

scala.Some 不能转换为 java.lang.String

在 Scalatra 中扩展 ResourceNotFoundException

java - Scala - 意外的 MapReduce 行为 - 偶数的平方

scala - 为什么在 Play Framework 中有一个build.gradle和一个build.sbt?

scala - SBT:插件依赖项和项目类路径