罐子和Spark的sbt-assembly行为

时间:2019-07-19 09:23:36

标签: scala sbt sbt-assembly sbt-native-packager

我对sbt汇编的行为有疑问:
当我使用此配置时:

  assemblyMergeStrategy in assembly := {
  case PathList("org", "aopalliance", xs@_*) => MergeStrategy.last
  case PathList("javax", "inject", xs@_*) => MergeStrategy.last
  case PathList("javax", "servlet", xs@_*) => MergeStrategy.last
  case PathList("javax", "activation", xs@_*) => MergeStrategy.last
  case PathList("org", "apache", xs@_*) => MergeStrategy.last
  case PathList("com", "google", xs@_*) => MergeStrategy.last
  case PathList("com", "esotericsoftware", xs@_*) => MergeStrategy.last
  case PathList("com", "codahale", xs@_*) => MergeStrategy.last
  case PathList("com", "yammer", xs@_*) => MergeStrategy.last
  case "about.html" => MergeStrategy.rename
  case "META-INF/ECLIPSEF.RSA" => MergeStrategy.last
  case "META-INF/MANIFEST.MF" => MergeStrategy.discard
  case "META-INF/mailcap" => MergeStrategy.last
  case "META-INF/mimetypes.default" => MergeStrategy.last
  case "plugin.properties" => MergeStrategy.last
  case "log4j.properties" => MergeStrategy.last
  case "git.properties" => MergeStrategy.discard
  case x => MergeStrategy.first
  case x =>
    val oldStrategy = (assemblyMergeStrategy in assembly).value
    oldStrategy(x)
}

我的输出jar约为109MB,其中包括spark库,即使我将其设置为提供的

但是当我使用它时:

  assemblyMergeStrategy in assembly := {
  case "src/test/resources/library.properties" => MergeStrategy.discard
  case PathList("META-INF", xs@_*) => MergeStrategy.discard
  case x => MergeStrategy.first
}  

我的Jar大约有10MB。你知道为什么吗?

1 个答案:

答案 0 :(得分:0)

在第二种策略中,您将丢弃依赖项jar中的所有META-INF文件夹(因此这些文件不会复制到远端jar中)

无论如何,您都可以解压缩两个jar文件并检查内部内容以进行比较