smddzcy
smddzcy

Reputation: 443

sbt-assembly deduplicate error with org.apache.arrow

I am using sbt 1.2.8 and sbt-assembly 0.14.9. I'm trying to build a fat JAR for my project that uses Spark + Akka + gRPC. I had many deduplication errors at first; I managed solved all but 1, and I couldn't find a way to solve this one for hours.

Here's the error message I get from 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

Here's my 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)
}

I am probably missing something in assemblyMergeStrategy (or have something extra).

Upvotes: 3

Views: 1763

Answers (3)

Alejandro Alcalde
Alejandro Alcalde

Reputation: 6220

I think as your conflict is with the file git.properties you could add a case for that file:

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

Being the full merge strategy the following:

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)
}

Try it and see if it fixed the problem

Upvotes: 0

smddzcy
smddzcy

Reputation: 443

Updating assemblyMergeStrategy to this fixed the issue:

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
}

Note that case PathList("META-INF", xs @ _*) => part comes from the default merge strategy of sbt-assembly, I just changed the last bit case _ => MergeStrategy.deduplicate to case _ => MergeStrategy.first.

Upvotes: 7

Tushar Walzade
Tushar Walzade

Reputation: 3809

In my case, I used the following code in build.sbt, which conditionally takes the first file if found any duplicates while building -

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

Upvotes: 3

Related Questions