为什么错误“不是有效的命令:assembly-merge-strategy”?

时间:2014-08-05 19:13:41

标签: sbt sbt-assembly

我有以下build.sbt文件。

import AssemblyKeys._

name := "approxstrmatch"

version := "1.0"

scalaVersion := "2.10.4"

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

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

// My merge strategy is specified here.

lazy val app = Project("approxstrmatch", file("approxstrmatch"),
    settings = buildSettings ++ assemblySettings ++ Seq(
    mergeStrategy in assembly <<= (mergeStrategy in assembly) { (old) =>
    {
        case PathList("javax", "servlet", xs @ _*)         => MergeStrategy.first
        case PathList("javax", "transaction", xs @ _*)     => MergeStrategy.first
        case PathList("javax", "mail", xs @ _*)     => MergeStrategy.first
        case PathList("javax", "activation", xs @ _*)     => MergeStrategy.first
        case PathList(ps @ _*) if ps.last endsWith ".html" => MergeStrategy.first
        case "application.conf" => MergeStrategy.concat
        case "unwanted.txt"     => MergeStrategy.discard
        case x => old(x)
        }
    })
  )

mainClass in assembly := Some("approxstrmatch.JaccardScore")
// jarName in assembly := "approstrmatch.jar"

当我执行以下命令sbt assembly-merge-strategy时,出现了一个我不明白的错误。任何帮助表示赞赏。

approxstrmatch]$ sbt assembly-merge-strategy
[info] Loading project definition from /apps/sameert/software/approxstrmatch/project
[info] Set current project to approxstrmatch (in buildfile:/apps/sameert/software/approxstrmatch/)
[error] Not a valid command: assembly-merge-strategy
[error] No such setting/task

3 个答案:

答案 0 :(得分:0)

我的理解告诉我sbt-assembly插件中没有assembly-merge-strategy任务(我只能怀疑你在构建中使用该插件)。

按照https://github.com/sbt/sbt-assembly#assembly-task中的描述执行assembly &#34;这是一个非常棒的新程序集任务,它将编译您的项目,运行测试,然后打包您的类文件和所有依赖项到一个JAR文件&#34;

答案 1 :(得分:0)

有一个名为assemblyMergeStrategy的设置(又名assembly-merge-strategy)。只是你不会直接使用它。 sbt-assembly使用它的方式限定为assembly任务:

mergeStrategy in assembly <<= ....

所以这就是你要从shell中调用它的方法:

$ sbt assembly::assemblyMergeStrategy
[info] blabla other things...
[info] <function1>

答案 2 :(得分:0)

在build.sbt中添加assemblySettings将有助于