Why Maven assembly works when SBT assembly find conflicts

后端 未结 3 742
日久生厌
日久生厌 2021-02-08 11:54

The title could also be:
What are the differences between Maven and SBT assembly plugins.

I have found this to be an issue, while migrating a proje

3条回答
  •  不思量自难忘°
    2021-02-08 12:29

    Extension to Alexey Romanov answer.

    I have also updated my project with detailed explanation, so you might want to check it out.

    Following the advice

    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.

    I compared the fat-jars produced by maven and sbt with

    • MergeStrategy.first, that showed some extra files
    • MergeStrategy.last, that showed binary differences & extra files

    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

    Conclusion

    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.

    Whereas sbt-assembly mixes all the class files, resolving conflicts locally, file by file.

    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.

提交回复
热议问题