How to get sbt-assembly merge right?

旧街凉风 提交于 2020-01-24 09:39:33

问题


In our Scala/Scalatra project, we have this merge policy for the plugin 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

What would be the right merge logic here?

Versions:

Scala : 2.11.7
SBT : 0.13.9
sbt-assembly: 0.13.0


回答1:


I do not think, it is a matter of "merge-strategy", but more of the libs and their dependencies you are using.

Who "pulls" these dependencies? Which libraries are you using concretely?

One way to restrict is to use excludeAll (and similar) with dependency declaration. (see library management in SBT ), e.g.

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")
  )



回答2:


My original issue was solved with:

assemblyMergeStrategy in assembly := {
  case PathList("org", "apache", "commons", "collections", xs @ _*) =>
      MergeStrategy.last
  case PathList("mime.types") =>
      MergeStrategy.last
  case x =>
      val oldStrategy = (assemblyMergeStrategy in assembly).value
      oldStrategy(x)
}


来源:https://stackoverflow.com/questions/32497280/how-to-get-sbt-assembly-merge-right

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!