Anji Anji - 2 months ago 12
Scala Question

Scala Build failing?

I am new to scala when Iam trying to execute sbt update I am getting

[error] /home/workspace/Scala/SparkTwitterStreaming/project/project/build.scala:1: expected class or object definition
[error] name := "SparkTwitterStreaming"
[error] ^
[error] /home/workspace/Scala/SparkTwitterStreaming/project/project/build.scala:2: expected class or object definition
[error] version := "1.0"
[error] ^
[error] /home/workspace/Scala/SparkTwitterStreaming/project/project/build.scala:3: expected class or object definition
[error] scalaVersion := "2.11.6"
[error] ^
[error] /home/workspace/Scala/SparkTwitterStreaming/project/project/build.scala:5: expected class or object definition
[error] libraryDependencies += "org.apache.spark" % "spark-core_2.11" % "1.6.2"
[error] ^
[error] /home/workspace/Scala/SparkTwitterStreaming/project/project/build.scala:6: expected class or object definition
[error] libraryDependencies += "com.typesafe" % "config" % "1.3.0"
[error] ^
[error] 5 errors found


build.scala
/
build.sbt
??

name := "SparkTwitterStreaming"

version := "1.0"

scalaVersion := "2.11.6"

libraryDependencies += "org.apache.spark" % "spark-core_2.11" % "1.6.2"

libraryDependencies += "com.typesafe" % "config" % "1.3.0"

Answer

It looks like you are confusing .scala and .sbt files. SBT allows defining build in two different ways. .scala files are, well, normal Scala files, so they can't have code (and name := "SparkTwitterStreaming" etc. in SBT are just Scala code) on top level, it has to be inside a trait/class/object. SBT itself takes care of wrapping .sbt files in this way.

SparkTwitterStreaming/project/project/build.scala also looks wrong: there are cases in SBT when you'd use a file under project/project, but this isn't one of them. You probably want to move this file to SparkTwitterStreaming/build.sbt.