使用org.apache.arrow进行sbt-assembly重复数据删除错误

时间:2019-01-08 15:01:02

标签: scala apache-spark sbt sbt-assembly

我正在使用sbt 1.2.8和sbt-assembly 0.14.9。我正在尝试为使用Spark + Akka + gRPC的项目构建胖JAR。一开始我有很多重复数据删除错误;我设法解决了除1之外的所有问题,而且几个小时都找不到解决该问题的方法。

这是我从sbt assembly得到的错误消息:

[error] (assembly) deduplicate: different file contents found in the following:
[error] /Users/samedduzcay/.ivy2/cache/org.apache.arrow/arrow-vector/jars/arrow-vector-0.10.0.jar:git.properties
[error] /Users/samedduzcay/.ivy2/cache/org.apache.arrow/arrow-format/jars/arrow-format-0.10.0.jar:git.properties
[error] /Users/samedduzcay/.ivy2/cache/org.apache.arrow/arrow-memory/jars/arrow-memory-0.10.0.jar:git.properties

这是我的build.sbt

import sbt.Keys._
import sbtassembly.AssemblyPlugin.autoImport.PathList

name := "xxx"

version := "1.0"

lazy val sv = "2.11.12"
scalaVersion := sv

lazy val akkaVersion = "2.5.19"
lazy val sparkVersion = "2.4.0"

enablePlugins(AkkaGrpcPlugin)
enablePlugins(JavaAgent)
javaAgents += "org.mortbay.jetty.alpn" % "jetty-alpn-agent" % "2.0.9" % "runtime;test"

test in assembly := {}
logLevel in assembly := Level.Debug

lazy val root = (project in file(".")).
settings(
  inThisBuild(List(
    organization := "com.smddzcy",
    scalaVersion := sv
  )),
  name := "xxx",
  libraryDependencies ++= Seq(
    "org.apache.spark" %% "spark-core" % sparkVersion,
    "org.apache.spark" %% "spark-sql" % sparkVersion,
    "org.mariadb.jdbc" % "mariadb-java-client" % "2.3.0",
    "com.typesafe.akka" %% "akka-actor" % akkaVersion,
    "com.typesafe.akka" %% "akka-protobuf" % akkaVersion,
    "com.typesafe.akka" %% "akka-stream" % akkaVersion,
    // "com.google.guava" % "guava" % "27.0.1-jre" % Compile,
    // "org.apache.httpcomponents" % "httpcore" % "4.4.10" % Compile,
    "com.typesafe.akka" %% "akka-stream-testkit" % akkaVersion % Test,
    "org.scalatest" %% "scalatest" % "3.0.5" % Test
  )
)

assemblyMergeStrategy in assembly := {
  case PathList(pl@_*) if pl.contains("log4j.properties") => MergeStrategy.concat
  case PathList("META-INF", "io.netty.versions.properties") => MergeStrategy.last
  case PathList("org", "aopalliance", xs@_*) => MergeStrategy.first
  case PathList("javax", "inject", xs@_*) => MergeStrategy.first
  case PathList("javax", "servlet", xs@_*) => MergeStrategy.first
  case PathList("javax", "activation", xs@_*) => MergeStrategy.first
  case PathList("org", "commons-collections", x@_*) => MergeStrategy.first
  case PathList("org", "apache", xs@_*) => MergeStrategy.first
  case PathList("com", "google", xs@_*) => MergeStrategy.first
  case "about.html" => MergeStrategy.rename
  case "META-INF/ECLIPSEF.RSA" => MergeStrategy.first
  case "META-INF/mailcap" => MergeStrategy.first
  case "META-INF/mimetypes.default" => MergeStrategy.first
  case "plugin.properties" => MergeStrategy.first
  case "application.conf" => MergeStrategy.concat
  case "reference.conf" => MergeStrategy.concat
  case x =>
    val oldStrategy = (assemblyMergeStrategy in assembly).value
    oldStrategy(x)
}

我可能在assemblyMergeStrategy中缺少了一些东西(或有其他东西)。

3 个答案:

答案 0 :(得分:5)

assemblyMergeStrategy更新为此问题:

assemblyMergeStrategy in assembly := {
  case PathList("META-INF", xs @ _*) =>
    xs map {_.toLowerCase} match {
      case "manifest.mf" :: Nil | "index.list" :: Nil | "dependencies" :: Nil =>
        MergeStrategy.discard
      case ps @ x :: xs if ps.last.endsWith(".sf") || ps.last.endsWith(".dsa") =>
        MergeStrategy.discard
      case "plexus" :: xs =>
        MergeStrategy.discard
      case "services" :: xs =>
        MergeStrategy.filterDistinctLines
      case "spring.schemas" :: Nil | "spring.handlers" :: Nil =>
        MergeStrategy.filterDistinctLines
      case _ => MergeStrategy.first
    }
  case "application.conf" => MergeStrategy.concat
  case "reference.conf" => MergeStrategy.concat
  case _ => MergeStrategy.first
}

请注意,case PathList("META-INF", xs @ _*) =>部分来自默认的合并策略sbt-assembly,我只是将最后一位case _ => MergeStrategy.deduplicate更改为case _ => MergeStrategy.first

答案 1 :(得分:3)

就我而言,我在 build.sbt 中使用了以下代码,如果在构建时发现重复,则有条件地获取第一个文件-

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

答案 2 :(得分:0)

我认为由于您与文件git.properties的冲突,您可以为此文件添加一个案例:

case "git.properties"                              => MergeStrategy.first
// or
case "git.properties"                              => MergeStrategy.concat

以下是完全合并策略:

assemblyMergeStrategy in assembly := {
  // ... other directives
  case "application.conf"                            => MergeStrategy.concat
  case "log4j.properties"                            => MergeStrategy.first
  case "unwanted.txt"                                => MergeStrategy.discard
  // ... other directives
  case "git.properties"                              => MergeStrategy.first
  // or maybe: case "git.properties"                              => MergeStrategy.concat
  case x =>
    val oldStrategy = (assemblyMergeStrategy in assembly).value
    oldStrategy(x)
}

尝试一下,看看是否能解决问题