3

作为 sbt 和 sbt-assembly 插件的新手,我对如何处理涉及我试图打包的依赖项中不同类定义的构建感到困惑。

[error] (*:assembly) deduplicate: different file contents found in the following:
[error] /Users/dm/.ivy2/cache/org.apache.tika/tika-app/jars/tika-app-1.3.jar:javax/xml/XMLConstants.class
[error] /Users/dm/.ivy2/cache/stax/stax-api/jars/stax-api-1.0.1.jar:javax/xml/XMLConstants.class
[error] /Users/dm/.ivy2/cache/xml-apis/xml-apis/jars/xml-apis-1.3.03.jar:javax/xml/XMLConstants.class

我已经添加:

mergeStrategy in assembly <<= (mergeStrategy in assembly) { (old) =>
  {
    case PathList("javax", "xml", xs @ _*) => MergeStrategy.first
  }
}

到我的 build.sbt 文件,但我仍然收到上面的错误(无论它是否在构建文件中)。任何指导将不胜感激。

谢谢,

大学教师

4

2 回答 2

5

我想你很接近。确保在assemblySettings加载后添加任何重新布线,并将您未处理的任何模式传递给默认策略:

assemblySettings

mergeStrategy in assembly <<= (mergeStrategy in assembly) { (old) =>
  {
    case PathList("javax", "xml", xs @ _*) => MergeStrategy.first
    case _ => old
  }
}
于 2013-08-24T01:30:29.817 回答
3

只是一个更新——使用当前的 sbt (0.13.8) 和 sbt-assembly (0.13.0) 版本,Eugene 的代码变为:

assemblyMergeStrategy in assembly := {
  case PathList("javax", "xml", xs @ _*) => MergeStrategy.first
  case x =>
    val oldStrategy = (assemblyMergeStrategy in assembly).value
    oldStrategy(x)
}
于 2015-06-09T18:36:55.513 回答