使用sbt程序集构建胖jar时build.sbt中的重复数据删除错误

时间:2014-09-19 02:03:31

标签: scala sbt sbt-assembly

我正在尝试创建一个包含spark和restlet框架组合的胖jar,但我不断收到此重复数据删除错误。

这是运行 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

这是我的 plugins.sbt 文件

logLevel := Level.Warn

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

这是我的 build.sbt 文件

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"

我不确定如何修复它。感谢是否有人可以提供帮助!

1 个答案:

答案 0 :(得分:2)

问题是sbt-assembly无法选择要拾取的META-INF / ECLIPSEF.RSA文件。试试这个以排除所有这些文件:

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

如果你真的需要jar中的一些RSA密钥:

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

(或者不要在excludedFiles中提及适当的基数)