Danny Ellis Jr.
Danny Ellis Jr.

Reputation: 1706

Where's the error in this Scala code?

I am brand new to Scala and trying to experiment with AWS Lambda functions. I am following this article: https://aws.amazon.com/blogs/compute/writing-aws-lambda-functions-in-scala/

I created a build.sbt file with this code.

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

However, when I try to compile I get one of several errors, depending on how I try to fix it. One such error is this:

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

This is pretty much totally foreign to me.

Upvotes: 0

Views: 94

Answers (1)

Tyler
Tyler

Reputation: 18187

I believe you have a loose angle bracket on this line:

mergeStrategy in assembly <

and that the syntax you are looking for is this:

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

It might also be:

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

Here is a link to the sbt-assembly project you are using to create the JAR. There are more examples there.


Edit for your comment:

The merge strategy needs to be part of the 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
    }
  )

Upvotes: 2

Related Questions