Why Maven assembly works when SBT assembly find conflicts

后端 未结 3 743
日久生厌
日久生厌 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:34

    It seems maven-assembly-plugin resolves conflicts equivalently to MergeStrategy.first (not sure if it's completely equivalent) by just picking one of the files in an unspecified way when jar-with-dependencies is used (since it only has one phase):

    If two or more elements (e.g., file, fileSet) select different sources for the same file for archiving, only one of the source files will be archived.

    As per version 2.5.2 of the assembly plugin, the first phase to add the file to the archive "wins". The filtering is done solely based on name inside the archive, so the same source file can be added under different output names. The order of the phases is as follows: 1) FileItem 2) FileSets 3) ModuleSet 4) DepenedencySet and 5) Repository elements.

    Elements of the same type will be processed in the order they appear in the descriptors. If you need to "overwrite" a file included by a previous set, the only way to do this is to exclude that file from the earlier set.

    Note that this behaviour was slightly different in earlier versions of the assembly plugin.

    Even if one of the conflicting files would work for all of your dependencies (which isn't necessarily so), Maven doesn't know which one, so you can just silently get the wrong result. Silently at build-time, I mean; at runtime you can get e.g. AbstractMethodError, or again just a wrong result.

    You can influence which file gets picked by writing your own descriptor, but it's horribly verbose, there's no equivalent to just writing MergeStrategy.first/last (and concat/discard are not allowed).

    The SBT plugin could do the same: default to a strategy when you don't specify one, but then, well, you could silently get the wrong result.

提交回复
热议问题