1

I am trying to understand how to write a well-written build.sbt file, and followed a tutorial on youtube. In that tutorial an object is created similar as below, but what I have written gives the shown error.

What am I doing wrong?

I have tried to remove blank lines between imports and the object declaration without any change.

import sbt._
import sbt.Keys._

object BuildScript extends Build {
  lazy val commonSettings = Seq(
  organization := "me",
  version := "0.1.0",
  scalaVersion := "2.11.4"
 )
 lazy val root = (project in file(".")).
  settings(commonSettings: _*).
  settings(
    name := "deepLearning",
    libraryDependencies += "org.deeplearning4j" % "deeplearning4j-core" % "0.4-rc3.4"
  )}

error message:
error: illegal start of simple expression
object BuildScript extends Build {
^
[error] Error parsing expression.  Ensure that there are no blank lines    within a setting.

I think this thread actually explains it: What is the difference between build.sbt and build.scala?

I feel that the edit made by chris martin on this post was unnecessary, but can't reject it.

Community
  • 1
  • 1
stian
  • 1,947
  • 5
  • 25
  • 47

2 Answers2

3

I think your tutorial was out of date. Using a recent version of sbt (0.13+ or so) you really want to do this:

lazy val commonSettings = Seq(
  organization := "me",
  version := "0.1.0",
  scalaVersion := "2.11.4"
)

lazy val root = (project in file(".")).
  settings(commonSettings).
  settings(
    name := "deepLearning",
    libraryDependencies += "org.deeplearning4j" % "deeplearning4j-core" % "0.4-rc3.4"
  )

If your project doesn't have any subprojects, though, the commonSettings val is somewhat superfluous, and you can just inline it:

lazy val root = (project in file(".")).
  settings(
    organization := "me",
    name := "deepLearning",
    version := "0.1.0",

    scalaVersion := "2.11.4",
    libraryDependencies += "org.deeplearning4j" % "deeplearning4j-core" % "0.4-rc3.4"
  )

If you do have subprojects, and wind up with a lot of common settings, you may want to pull them out into an autoplugin, but that's a more advanced concept.

gregsymons
  • 317
  • 2
  • 11
0

There are two ways to fix this:

  1. Do object BuildScript extends Build { ... } and use .scala extension for the build file. I think this way is the recommended long term Sbt build file style.
  2. Change build definition to gregsymons's answer and keep the .sbt extension.
Alex
  • 247
  • 3
  • 12
  • I believe it is fully possible to have a (build).sbt ending at the project root for the scala build tool. I think that the other stack overflow thread explains things well. – stian Dec 02 '15 at 00:55