标题也可以是:
Maven 和 SBT 组装插件之间有什么区别?
在将项目从 Maven 迁移到 SBT 时,我发现这是一个问题。
为了描述这个问题,我创建了一个示例项目,其中的依赖项我发现它的行为有所不同,具体取决于构建工具。
https://github.com/atais/mvn-sbt-assemble 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>
...
延伸至阿列克谢·罗曼诺夫 答案 https://stackoverflow.com/a/50464199/1549135.
我也更新了我的项目 https://github.com/atais/mvn-sbt-assembly有详细的解释,所以你可能想检查一下。
遵循建议
您可以通过解压 Maven 生成的 jar 和 SBT 错误消息中的依赖项 jar,然后检查 Maven 使用哪个 .class 文件来验证这种情况。
我比较了fat-jars
由。。。生产maven
and sbt
with
-
MergeStrategy.first
,显示了一些额外的文件
-
MergeStrategy.last
,显示二进制差异和额外文件
我已采取下一步并检查了fat-jars
反对依赖关系sbt
发现冲突,具体为:
- jcl-over-slf4j-1.7.7.jar http://central.maven.org/maven2/org/slf4j/jcl-over-slf4j/1.7.7/jcl-over-slf4j-1.7.7.jar
- commons-logging-1.1.1.jar http://central.maven.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar
结论
maven-assembly-plugin
解决冲突jar
等级。
当它发现任何冲突时,它会选择第一个jar
并简单地忽略对方的所有内容。
Whereas sbt-assembly
混合所有的class
文件,在本地逐个文件解决冲突。
我的理论会是,如果你的fat-jar
用做的maven-assembly-plugin
有效,你可以
指定MergeStrategy.first
对于所有的冲突sbt
。
他们唯一的区别是,jar
生产与sbt
将会更大,包含被忽略的额外类maven
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)