我正在尝试将历史悠久的Scala / Spark SBT项目升级到SBT 1.1.0版。它使用Scala 2.10.6,如build.sbt
文件中所指定。尚不清楚build.sbt
文件的哪个SBT版本已实现,但大概是0.12.x甚至更早。
我无法迁移assemblyExcludedJars
文件中的build.sbt
行:
import sbt.Keys.{libraryDependencies, _}
import sbtassembly.AssemblyKeys.assemblyExcludedJars
[...]
lazy val sparkSettings = Seq(
libraryDependencies ++= Seq(
"org.apache.spark" %% "spark-sql" % "1.6.0",
[...],
assemblyExcludedJars in assembly <<= (fullClasspath in assembly) map { cp =>
val excludes = Set(
"minlog-1.2.jar",
[...]
)
cp filter { jar => excludes(jar.data.getName) }
}
)
正如migration guide所指出的那样,我不再支持<<=
,因此我将其更改为:=
。
在更改后运行sbt assembly
时,会引发以下错误:
$ sbt assembly
[info] Loading settings from idea.sbt ...
[info] Loading global plugins from /home/XXX/.sbt/1.0/plugins
[info] Loading settings from assembly.sbt ...
[info] Loading project definition from YYY/project
YYY/build.sbt:49: error: type mismatch;
found : sbt.Def.Initialize[sbt.Task[Seq[sbt.internal.util.Attributed[java.io.File]]]]
required: sbt.Keys.Classpath
(which expands to) Seq[sbt.internal.util.Attributed[java.io.File]]
assemblyExcludedJars in assembly := (fullClasspath in assembly) map { cp =>
^
[error] sbt.compiler.EvalException: Type error in expression
[error] sbt.compiler.EvalException: Type error in expression
[error] Use 'last' for the full log.
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore?
我在SBT文档中找不到关于这条线应该做什么的很多内容。虽然assembly
的类型似乎发生了变化,但我觉得它很混乱。
我也在IntelliJ Idea中查看此内容,但它实际上表示错误Cannot resolve symbol assembly
。
如何正确迁移此构建文件?
答案 0 :(得分:1)
要重写assemblyExcludedJars
设置,它应该如下所示:
assemblyExcludedJars in assembly := {
val cp = (fullClasspath in assembly).value
val excludes = Set("minlog-1.2.jar", [...])
cp filter { jar => excludes(jar.data.getName) }
}
仅替换<<=
运算符会失败,因为:=
运算符会在右侧取代任务的结果类型而不是Initialize[Task[...]]
答案 1 :(得分:0)
有时assemblyExcludedJars
不起作用。
肮脏的方法是在合并策略中使用defind。
assemblyMergeStrategy in assembly :={
case PathList("lib", "static", "Windows", xs @ _*) => MergeStrategy.discard
case PathList("META-INF", xs @ _*) => MergeStrategy.discard
case PathList("com","sun", xs @ _*)=> MergeStrategy.discard
case PathList("mx4j", xs @ _*)=> MergeStrategy.discard
case PathList("org","aopalliance", xs @ _*)=> MergeStrategy.discard
case PathList("org","apache","jasper", xs @ _*)=> MergeStrategy.discard
case PathList("javax", xs @ _*)=> MergeStrategy.discard
case PathList("org", "apache", "jasper", xs @ _*)=> MergeStrategy.discard
case PathList("org", "fusesource", xs @ _*)=> MergeStrategy.discard
case PathList("org", "objenesis", xs @ _*)=> MergeStrategy.discard
case PathList("org", "scalactic", xs @ _*)=> MergeStrategy.discard
case PathList("org", "scalactic", xs @ _*)=> MergeStrategy.discard
case PathList("parquet", xs @ _*)=> MergeStrategy.discard
case PathList("javax", xs @ _*)=> MergeStrategy.discard
case PathList("org", "apache", "jasper", xs @ _*)=> MergeStrategy.discard
case PathList("org", "fusesource", xs @ _*)=> MergeStrategy.discard
case PathList("org", "objenesis", xs @ _*)=> MergeStrategy.discard
case PathList("org", "scalactic", xs @ _*)=> MergeStrategy.discard
case PathList("parquet", xs @ _*)=> MergeStrategy.discard
case PathList("akka", xs @ _*)=> MergeStrategy.discard
case PathList("antlr", xs @ _*)=> MergeStrategy.discard
case PathList("assets", xs @ _*)=> MergeStrategy.discard
case PathList("au", xs @ _*)=> MergeStrategy.discard
case PathList("breeze", xs @ _*)=> MergeStrategy.discard
case PathList("codegen", xs @ _*)=> MergeStrategy.discard
case PathList("contribs", xs @ _*)=> MergeStrategy.discard
case PathList("darwin", xs @ _*)=> MergeStrategy.discard
case PathList("db", xs @ _*)=> MergeStrategy.discard
case PathList("edu", xs @ _*)=> MergeStrategy.discard
case PathList("fr", xs @ _*)=> MergeStrategy.discard
case PathList("hbase-webapps", xs @ _*)=> MergeStrategy.discard
case PathList("html", xs @ _*)=> MergeStrategy.discard
case PathList("i18n", xs @ _*)=> MergeStrategy.discard
case PathList("images", xs @ _*)=> MergeStrategy.discard
case PathList("io", xs @ _*)=> MergeStrategy.discard
case PathList("javaewah", xs @ _*)=> MergeStrategy.discard
case PathList("javassist", xs @ _*)=> MergeStrategy.discard
case PathList("javolution", xs @ _*)=> MergeStrategy.discard
case PathList("jersey", xs @ _*)=> MergeStrategy.discard
case PathList("jline", xs @ _*)=> MergeStrategy.discard
case PathList("jodd", xs @ _*)=> MergeStrategy.discard
case PathList("joptsimple", xs @ _*)=> MergeStrategy.discard
case PathList("junit", xs @ _*)=> MergeStrategy.discard
case PathList("kafka", xs @ _*)=> MergeStrategy.discard
case PathList("linux", xs @ _*)=> MergeStrategy.discard
case PathList("macrocompat", xs @ _*)=> MergeStrategy.discard
case PathList("mozilla", xs @ _*)=> MergeStrategy.discard
case PathList("net", xs @ _*)=> MergeStrategy.discard
case PathList("nu", xs @ _*)=> MergeStrategy.discard
case PathList("ooyala", xs @ _*)=> MergeStrategy.discard
case PathList("OSGI-OPT", xs @ _*)=> MergeStrategy.discard
case PathList("py4j", xs @ _*)=> MergeStrategy.discard
case PathList("scala", xs @ _*)=> MergeStrategy.discard
case PathList("schema", xs @ _*)=> MergeStrategy.discard
case PathList("shaded", xs @ _*)=> MergeStrategy.discard
case PathList("shapeless", xs @ _*)=> MergeStrategy.discard
case PathList("snappydata", xs @ _*)=> MergeStrategy.discard
case PathList("spark", xs @ _*)=> MergeStrategy.discard
case PathList("spire", xs @ _*)=> MergeStrategy.discard
case PathList("spray", xs @ _*)=> MergeStrategy.discard
case PathList("tables", xs @ _*)=> MergeStrategy.discard
case PathList("templates", xs @ _*)=> MergeStrategy.discard
case PathList("twitter4j", xs @ _*)=> MergeStrategy.discard
case PathList("webapps", xs @ _*)=> MergeStrategy.discard
case PathList("win32", xs @ _*)=> MergeStrategy.discard
case PathList("org", "antlr",xs @ _*)=> MergeStrategy.discard
case PathList("org", "bouncycastle",xs @ _*)=> MergeStrategy.discard
case PathList("org", "cliffc",xs @ _*)=> MergeStrategy.discard
case PathList("org", "cloudera",xs @ _*)=> MergeStrategy.discard
case PathList("org", "codehaus",xs @ _*)=> MergeStrategy.discard
case PathList("org", "datanucleus",xs @ _*)=> MergeStrategy.discard
case PathList("org", "dmg",xs @ _*)=> MergeStrategy.discard
case PathList("org", "eclipse",xs @ _*)=> MergeStrategy.discard
case PathList("org", "eigenbase",xs @ _*)=> MergeStrategy.discard
case PathList("org", "flywaydb",xs @ _*)=> MergeStrategy.discard
case PathList("org", "glassfish",xs @ _*)=> MergeStrategy.discard
case PathList("org", "h2",xs @ _*)=> MergeStrategy.discard
case PathList("org", "hamcrest",xs @ _*)=> MergeStrategy.discard
case PathList("org", "I0Itec",xs @ _*)=> MergeStrategy.discard
case PathList("org", "iq80",xs @ _*)=> MergeStrategy.discard
case PathList("org", "jamon",xs @ _*)=> MergeStrategy.discard
case PathList("org", "jboss",xs @ _*)=> MergeStrategy.discard
case PathList("org", "jcodings",xs @ _*)=> MergeStrategy.discard
case PathList("org", "jets3t",xs @ _*)=> MergeStrategy.discard
case PathList("org", "joda",xs @ _*)=> MergeStrategy.discard
case PathList("org", "joni",xs @ _*)=> MergeStrategy.discard
case PathList("org", "jpmml",xs @ _*)=> MergeStrategy.discard
case PathList("org", "junit",xs @ _*)=> MergeStrategy.discard
case PathList("org", "jvnet",xs @ _*)=> MergeStrategy.discard
case PathList("org", "j_paine",xs @ _*)=> MergeStrategy.discard
case PathList("org", "mortbay",xs @ _*)=> MergeStrategy.discard
case PathList("org", "netlib",xs @ _*)=> MergeStrategy.discard
case PathList("org", "omg",xs @ _*)=> MergeStrategy.discard
case PathList("org", "osgi",xs @ _*)=> MergeStrategy.discard
case PathList("org", "parboiled",xs @ _*)=> MergeStrategy.discard
case PathList("org", "parboiled2",xs @ _*)=> MergeStrategy.discard
case PathList("org", "roaringbitmap",xs @ _*)=> MergeStrategy.discard
case PathList("org", "rogach",xs @ _*)=> MergeStrategy.discard
case PathList("org", "scalatest",xs @ _*)=> MergeStrategy.discard
case PathList("org", "stringtemplate",xs @ _*)=> MergeStrategy.discard
case PathList("org", "supercsv",xs @ _*)=> MergeStrategy.discard
case PathList("org", "tukaani",xs @ _*)=> MergeStrategy.discard
case PathList("org", "uncommons",xs @ _*)=> MergeStrategy.discard
case PathList("org", "w3c",xs @ _*)=> MergeStrategy.discard
case PathList("org", "xerial",xs @ _*)=> MergeStrategy.discard
case PathList("org", "znerd",xs @ _*)=> MergeStrategy.discard
case PathList("org", "clearspring",xs @ _*)=> MergeStrategy.discard
case PathList("org", "esotericsoftware",xs @ _*)=> MergeStrategy.discard
case PathList("org", "facebook",xs @ _*)=> MergeStrategy.discard
case PathList("org", "fasterxml",xs @ _*)=> MergeStrategy.discard
case PathList("com", "gemstone",xs @ _*)=> MergeStrategy.discard
case PathList("com", "github",xs @ _*)=> MergeStrategy.discard
case PathList("com", "jamesmurty",xs @ _*)=> MergeStrategy.discard
case PathList("com", "jolbox",xs @ _*)=> MergeStrategy.discard
case PathList("com", "ning",xs @ _*)=> MergeStrategy.discard
case PathList("com", "pivotal",xs @ _*)=> MergeStrategy.discard
case PathList("com", "thoughtworks",xs @ _*)=> MergeStrategy.discard
case PathList("com", "univocity",xs @ _*)=> MergeStrategy.discard
case PathList("com", "vmware",xs @ _*)=> MergeStrategy.discard
case PathList("com", "yammer",xs @ _*)=> MergeStrategy.discard
case PathList("com", "zaxxer",xs @ _*)=> MergeStrategy.discard
case x => MergeStrategy.first
}