火花 + sbt-assembly: "deduplicate: different file contents found in the following"
spark + sbt-assembly: "deduplicate: different file contents found in the following"
我 运行 启动应用程序并想将测试 类 打包到 fat jar 中。奇怪的是我 运行 "sbt assembly" 成功了,但是 运行 "sbt test:assembly" 失败了。
我试过 sbt-assembly : including test classes,它对我的情况不起作用。
SBT 版本:0.13.8
build.sbt:
import sbtassembly.AssemblyPlugin._
name := "assembly-test"
version := "1.0"
scalaVersion := "2.10.5"
libraryDependencies ++= Seq(
("org.apache.spark" % "spark-core_2.10" % "1.3.1" % Provided)
.exclude("org.mortbay.jetty", "servlet-api").
exclude("commons-beanutils", "commons-beanutils-core").
exclude("commons-collections", "commons-collections").
exclude("commons-logging", "commons-logging").
exclude("com.esotericsoftware.minlog", "minlog").exclude("com.codahale.metrics", "metrics-core"),
"org.json4s" % "json4s-jackson_2.10" % "3.2.10" % Provided,
"com.google.inject" % "guice" % "4.0"
)
Project.inConfig(Test)(assemblySettings)
您必须在程序集中定义 mergeStratey,就像我在下面为我的 spark 应用所做的那样。
mergeStrategy in assembly <<= (mergeStrategy in assembly) { (old) =>
{
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/mailcap" => MergeStrategy.last
case "META-INF/mimetypes.default" => MergeStrategy.last
case "plugin.properties" => MergeStrategy.last
case "log4j.properties" => MergeStrategy.last
case x => old(x)
}
}
作为 Wesley Milano 的回答的补充,代码需要针对 sbt-assembly 插件的较新版本(即 0.13.0)进行一些调整,以防有人对弃用警告感到疑惑:
assemblyMergeStrategy in assembly := {
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/mailcap" => MergeStrategy.last
case "META-INF/mimetypes.default" => MergeStrategy.last
case "plugin.properties" => MergeStrategy.last
case "log4j.properties" => MergeStrategy.last
case x =>
val oldStrategy = (assemblyMergeStrategy in assembly).value
oldStrategy(x)
}
我 运行 启动应用程序并想将测试 类 打包到 fat jar 中。奇怪的是我 运行 "sbt assembly" 成功了,但是 运行 "sbt test:assembly" 失败了。
我试过 sbt-assembly : including test classes,它对我的情况不起作用。
SBT 版本:0.13.8
build.sbt:
import sbtassembly.AssemblyPlugin._
name := "assembly-test"
version := "1.0"
scalaVersion := "2.10.5"
libraryDependencies ++= Seq(
("org.apache.spark" % "spark-core_2.10" % "1.3.1" % Provided)
.exclude("org.mortbay.jetty", "servlet-api").
exclude("commons-beanutils", "commons-beanutils-core").
exclude("commons-collections", "commons-collections").
exclude("commons-logging", "commons-logging").
exclude("com.esotericsoftware.minlog", "minlog").exclude("com.codahale.metrics", "metrics-core"),
"org.json4s" % "json4s-jackson_2.10" % "3.2.10" % Provided,
"com.google.inject" % "guice" % "4.0"
)
Project.inConfig(Test)(assemblySettings)
您必须在程序集中定义 mergeStratey,就像我在下面为我的 spark 应用所做的那样。
mergeStrategy in assembly <<= (mergeStrategy in assembly) { (old) =>
{
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/mailcap" => MergeStrategy.last
case "META-INF/mimetypes.default" => MergeStrategy.last
case "plugin.properties" => MergeStrategy.last
case "log4j.properties" => MergeStrategy.last
case x => old(x)
}
}
作为 Wesley Milano 的回答的补充,代码需要针对 sbt-assembly 插件的较新版本(即 0.13.0)进行一些调整,以防有人对弃用警告感到疑惑:
assemblyMergeStrategy in assembly := {
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/mailcap" => MergeStrategy.last
case "META-INF/mimetypes.default" => MergeStrategy.last
case "plugin.properties" => MergeStrategy.last
case "log4j.properties" => MergeStrategy.last
case x =>
val oldStrategy = (assemblyMergeStrategy in assembly).value
oldStrategy(x)
}