问题描述
我正在尝试使用 SBT 和 sbt-assembly 生成一个胖 jar.作为一项要求,我需要在 jar 中添加其他非托管资源(目录).问题是 2 个目录上的文件具有相同的文件名和路径.因此,运行 assembly 会导致 copyResources 错误 - 重复映射错误.我想要的行为是如果文件已经存在,则丢弃另一个文件.有没有办法做到这一点?这行得通吗?
I am trying to generate a fat jar using SBT and sbt-assembly. As a requirement, there are other unmanaged resources (directories) that I need to add in the jar. The problem is there are files on 2 directories that have the same file name and path. So running assembly results to a copyResources error - a Duplicate Mappings error. The behaviour that I want is if the file is already existing, discard the other file. Is there a way to do this? Will this work?
unmanagedResources in Compile ~= (_.distinct)
有解决办法吗?有没有更好的解决方案?
Is it a solution? Is there a better solution?
推荐答案
也许是程序集插件的 合并策略设置对您来说已经足够了.试试这个:
Maybe the assembly plugin's merge strategy settings are sufficient for you. Try this:
mergeStrategy in assembly <<= (mergeStrategy in assembly) { (old) => {
case PathList("path", "to", "file", xs @ _*) =>
(xs map {_.toLowerCase}) match {
case ("myduplicatefile" :: Nil) => MergeStrategy.first
case _ => MergeStrategy.deduplicate
}
case x => old(x)
}
这篇关于SBT - 有没有办法忽略 copyResources 中的重复映射?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!