标题也可以是:
Maven 和 SBT 程序集插件之间有什么区别。
在将项目从 Maven 迁移到 SBT 时,我发现这是一个问题。
为了描述这个问题,我创建了一个示例项目,其中的依赖项根据构建工具的不同而表现不同。
https://github.com/atais/mvn-sbt-assembly
唯一的依赖是(sbt 风格)
"com.netflix.astyanax" % "astyanax-cassandra" % "3.9.0",
"org.apache.cassandra" % "cassandra-all" % "3.4",
我不明白的是,为什么
mvn package
成功创建了 fat jar 子,而 sbt assembly
产生冲突:[error] 39 errors were encountered during merge
[error] java.lang.RuntimeException: deduplicate: different file contents found in the following:
[error] /home/siatkowskim/.ivy2/cache/org.slf4j/jcl-over-slf4j/jars/jcl-over-slf4j-1.7.7.jar:org/apache/commons/logging/<some classes>
[error] /home/siatkowskim/.ivy2/cache/commons-logging/commons-logging/jars/commons-logging-1.1.1.jar:org/apache/commons/logging/<some classes>
...
[error] /home/siatkowskim/.ivy2/cache/com.github.stephenc.high-scale-lib/high-scale-lib/jars/high-scale-lib-1.1.2.jar:org/cliffc/high_scale_lib/<some classes>
[error] /home/siatkowskim/.ivy2/cache/com.boundary/high-scale-lib/jars/high-scale-lib-1.0.6.jar:org/cliffc/high_scale_lib/<some classes>
...
最佳答案
扩展到 Alexey Romanov answer .
我也更新了my project有详细的解释,所以你可能想看看。
听从建议
You can verify it for this case by unpacking the jar Maven produces and the dependency jars in SBT error message, then checking which .class file Maven used.
我比较了
fat-jars
制作人 maven
和 sbt
和MergeStrategy.first
,显示了一些额外的文件 MergeStrategy.last
,显示二进制差异和额外文件 我已经采取了下一步并检查了
fat-jars
针对依赖项 sbt
发现冲突,特别是:结论
maven-assembly-plugin
解决 jar
上的冲突等级。当它发现任何冲突时,它会选择第一个
jar
并且简单地忽略来自另一个的所有内容。而
sbt-assembly
混合所有 class
文件,在本地解决冲突,逐个文件。我的理论 会,如果你的
fat-jar
由 maven-assembly-plugin
制成工作,你可以指定
MergeStrategy.first
对于 sbt
中的所有冲突.他们唯一的区别是,
jar
用 sbt
制作会更大,包含被 maven
忽略的额外类.
关于maven - 为什么 Maven 程序集在 SBT 程序集发现冲突时工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50249818/