这个Scala代码中的错误在哪里?

时间:2017-04-18 20:26:50

标签: scala aws-lambda

我是Scala的新手并试图尝试使用AWS Lambda函数。我正在关注这篇文章:https://aws.amazon.com/blogs/compute/writing-aws-lambda-functions-in-scala/

我使用此代码创建了一个build.sbt文件。

javacOptions ++= Seq("-source", "1.8", "-target", "1.8", "-Xlint")

lazy val root = (project in file(".")).
  settings(
    name := "lambda-demo",
    version := "1.0",
    scalaVersion := "2.11.4",
    retrieveManaged := true,
    libraryDependencies += "com.amazonaws" % "aws-lambda-java-core" % "1.0.0",
    libraryDependencies += "com.amazonaws" % "aws-lambda-java-events" % "1.0.0"
  )

mergeStrategy in assembly <
   {
    case PathList("META-INF", xs @ _*) => MergeStrategy.discard
    case x => MergeStrategy.first
   }
}

然而,当我尝试编译时,我会遇到一些错误,具体取决于我如何尝试修复它。一个这样的错误就是:

/build.sbt:14: error: value < is not a member of sbt.TaskKey[sbt.File]
mergeStrategy in assembly <

这对我来说几乎是完全陌生的。

1 个答案:

答案 0 :(得分:2)

我相信你在这一行上有一个松散的尖括号:

mergeStrategy in assembly <

并且您要查找的语法是:

mergeStrategy in assembly := {
    case PathList("META-INF", xs @ _*) => MergeStrategy.discard
    case x => MergeStrategy.first
}

也可能是:

assemblyMergeStrategy in assembly := { /* Same case statements */ }

Here是您用于创建JAR的sbt-assembly项目的链接。那里有更多的例子。

编辑您的评论:

合并策略需要成为root.settings

的一部分
javacOptions ++= Seq("-source", "1.8", "-target", "1.8", "-Xlint")

lazy val root = (project in file(".")).
  settings(
    name := "lambda-demo",
    version := "1.0",
    scalaVersion := "2.11.4",
    retrieveManaged := true,
    libraryDependencies += "com.amazonaws" % "aws-lambda-java-core" % "1.0.0",
    libraryDependencies += "com.amazonaws" % "aws-lambda-java-events" % "1.0.0",
    assemblyMergeStrategy in assembly := {
      case PathList("META-INF", xs @ _*) => MergeStrategy.discard
      case x => MergeStrategy.first
    }
  )