为什么SBT程序集发现冲突时Maven程序集可以工作 [英] Why Maven assembly works when SBT assembly find conflicts
问题描述
标题也可以是:
Maven和SBT程序集插件之间有什么区别.
The title could also be:
What are the differences between Maven and SBT assembly plugins.
在将项目从Maven迁移到SBT时,我发现这是一个问题.
I have found this to be an issue, while migrating a project from Maven to SBT.
为了描述这个问题,我创建了一个示例项目,该项目依赖于构建工具,而我发现它们的行为有所不同.
To describe the problem I have created an example project with dependencies that I found to behave differently, depending on the build tool.
https://github.com/atais/mvn-sbt-assembly
唯一的依赖项是(sbt样式)
The only dependencies are (sbt style)
"com.netflix.astyanax" % "astyanax-cassandra" % "3.9.0",
"org.apache.cassandra" % "cassandra-all" % "3.4",
我不理解的是,为什么mvn package
成功创建胖子罐,而sbt assembly
却产生冲突:
and what I do not understand is, why mvn package
creates the fat jar successfully, while sbt assembly
gives conflicts:
[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答案.
我还用详细说明更新了我的项目,所以您可能想要看看.
Extension to Alexey Romanov answer.
I have also updated my project with detailed explanation, so you might want to check it out.
遵循建议
对于这种情况,您可以通过解压缩Maven生成的jar和SBT错误消息中的依赖jar,然后检查Maven使用了哪个.class文件来对此进行验证.
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.
我比较了maven
和sbt
产生的fat-jars
与
-
MergeStrategy.first
,其中显示了一些额外的文件 -
MergeStrategy.last
,显示二进制差异&多余的文件
MergeStrategy.first
, that showed some extra filesMergeStrategy.last
, that showed binary differences & extra files
我已经进行了下一步,并针对sbt
发现冲突的依赖项检查了fat-jars
,具体来说:
I have taken the next step and checked the fat-jars
against the dependencies sbt
found conflicts at, specifically:
- jcl-over-slf4j-1.7.7.jar
- commons-logging-1.1.1.jar
maven-assembly-plugin
解决了jar
级别的冲突.
当发现任何冲突时,它将选择第一个jar
,而忽略其他所有内容.
maven-assembly-plugin
resolves conflicts on jar
level.
When it finds any conflict, it picks the first jar
and simply ignores all the content from the other.
sbt-assembly
则混合所有class
文件,以逐个文件的方式在本地解决冲突.
Whereas sbt-assembly
mixes all the class
files, resolving conflicts locally, file by file.
我的理论将是,如果您用maven-assembly-plugin
制作的fat-jar
可行,则您可以
对于sbt
中的所有冲突,请指定MergeStrategy.first
.
它们唯一的区别是,用sbt
生成的jar
会更大,包含被maven
忽略的额外类.
My theory would be, that if your fat-jar
made with maven-assembly-plugin
works, you can
specify MergeStrategy.first
for all the conflicts in sbt
.
They only difference would be, that the jar
produced with sbt
will be even bigger, containing extra classes that were ignored by maven
.
这篇关于为什么SBT程序集发现冲突时Maven程序集可以工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!