Deduplication error in build.sbt when building a fat jar using sbt assembly
Asked Answered
C

1

1

I'm trying to create a fat jar of a combination of spark and restlet framework, but I keep getting this deduplication error.

This is the error for running sbt assembly:

    java.lang.RuntimeException: deduplicate: different file contents found in the following:
    /Users/ccd/.ivy2/cache/org.eclipse.jetty.orbit/javax.transaction/orbits/javax.transaction-1.1.1.v201105210645.jar:META-INF/ECLIPSEF.RSA
    /Users/ccd/.ivy2/cache/org.eclipse.jetty.orbit/javax.servlet/orbits/javax.servlet-3.0.0.v201112011016.jar:META-INF/ECLIPSEF.RSA
    /Users/ccd/.ivy2/cache/org.eclipse.jetty.orbit/javax.mail.glassfish/orbits/javax.mail.glassfish-1.4.1.v201005082020.jar:META-INF/ECLIPSEF.RSA
    /Users/ccd/.ivy2/cache/org.eclipse.jetty.orbit/javax.activation/orbits/javax.activation-1.1.0.v201105071233.jar:META-INF/ECLIPSEF.RSA
            at sbtassembly.Plugin$Assembly$.sbtassembly$Plugin$Assembly$$applyStrategy$1(Plugin.scala:253)
            at sbtassembly.Plugin$Assembly$$anonfun$15.apply(Plugin.scala:270)
            at sbtassembly.Plugin$Assembly$$anonfun$15.apply(Plugin.scala:267)
            at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:251)
            at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:251)
            at scala.collection.Iterator$class.foreach(Iterator.scala:727)
            at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
            at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
            at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
            at scala.collection.TraversableLike$class.flatMap(TraversableLike.scala:251)
            at scala.collection.AbstractTraversable.flatMap(Traversable.scala:105)
            at sbtassembly.Plugin$Assembly$.applyStrategies(Plugin.scala:272)
            at sbtassembly.Plugin$Assembly$.x$4$lzycompute$1(Plugin.scala:172)
            at sbtassembly.Plugin$Assembly$.x$4$1(Plugin.scala:170)
            at sbtassembly.Plugin$Assembly$.stratMapping$lzycompute$1(Plugin.scala:170)
            at sbtassembly.Plugin$Assembly$.stratMapping$1(Plugin.scala:170)
            at sbtassembly.Plugin$Assembly$.inputs$lzycompute$1(Plugin.scala:214)
            at sbtassembly.Plugin$Assembly$.inputs$1(Plugin.scala:204)
            at sbtassembly.Plugin$Assembly$.apply(Plugin.scala:230)
            at sbtassembly.Plugin$Assembly$$anonfun$assemblyTask$1.apply(Plugin.scala:373)
            at sbtassembly.Plugin$Assembly$$anonfun$assemblyTask$1.apply(Plugin.scala:370)
            at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
            at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:42)
            at sbt.std.Transform$$anon$4.work(System.scala:64)
            at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
            at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
            at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
            at sbt.Execute.work(Execute.scala:244)
            at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
            at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
            at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
            at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
            at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
            at java.util.concurrent.FutureTask.run(FutureTask.java:166)
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
            at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
            at java.util.concurrent.FutureTask.run(FutureTask.java:166)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
            at java.lang.Thread.run(Thread.java:724)
    [error] (*:assembly) deduplicate: different file contents found in the following:
    [error] /Users/ccd/.ivy2/cache/org.eclipse.jetty.orbit/javax.transaction/orbits/javax.transaction-1.1.1.v201105210645.jar:META-INF/ECLIPSEF.RSA
    [error] /Users/ccd/.ivy2/cache/org.eclipse.jetty.orbit/javax.servlet/orbits/javax.servlet-3.0.0.v201112011016.jar:META-INF/ECLIPSEF.RSA
    [error] /Users/ccd/.ivy2/cache/org.eclipse.jetty.orbit/javax.mail.glassfish/orbits/javax.mail.glassfish-1.4.1.v201005082020.jar:META-INF/ECLIPSEF.RSA
    [error] /Users/ccd/.ivy2/cache/org.eclipse.jetty.orbit/javax.activation/orbits/javax.activation-1.1.0.v201105071233.jar:META-INF/ECLIPSEF.RSA
    [error] Total time: 8 s, completed 19/09/2014 11:50:50 AM

This is my plugins.sbt file

logLevel := Level.Warn

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2")

And this is my build.sbt file

import AssemblyKeys._ // put this at the top of the file

name := "Spark_sbt2"

version := "1.1"

scalaVersion := "2.10.4"

libraryDependencies += "org.apache.spark" %% "spark-core" % "1.1.0"

libraryDependencies += "org.apache.spark" %% "spark-mllib" % "1.1.0"

libraryDependencies += "org.apache.spark" %% "spark-streaming" % "1.1.0"

libraryDependencies += "org.apache.httpcomponents" % "httpclient" % "4.3.5"

libraryDependencies += "org.restlet.jse" % "org.restlet" % "2.2.2"

libraryDependencies += "org.restlet.jse" % "org.restlet.ext.jackson" % "2.2.2"

resolvers += "Akka Repository" at "http://repo.akka.io/releases/"

resolvers += "Restlet" at "http://maven.restlet.org"

assemblySettings

jarName in assembly := "spark-assembly.jar"

I'm not sure how to fix it. Appreciate if anyone could help!

Capitulary answered 19/9, 2014 at 2:3 Comment(0)
G
2

The problem is sbt-assembly cannot choose which META-INF/ECLIPSEF.RSA file to pickup. Try this to exclude all such files:

excludedFiles in assembly <<=
(excludedFiles in assembly) {
  (old) => (bases) =>
    old(bases) ++ (bases flatMap (base =>
      (base / "META-INF/ECLIPSEF.RSA").get))
}

If you really need some RSA key inside jar:

assembledMappings in assembly <<= (assembledMappings in assembly) map { (old: File => Seq[(File, String)]) =>
  (f: File) => old(f) :+ (file("path/to/choosen/rsa/key"), "META-INF/ECLIPSEF.RSA")
}

(or don't mention it in excludedFiles for appropriate base)

Grandchild answered 19/9, 2014 at 2:59 Comment(1)
Thanks for the reply! Just comment that excludedFiles now becomes MergeStrategy.discard in sbtCapitulary

© 2022 - 2024 — McMap. All rights reserved.