Scala SBT and build.sbt syntax and examples

Note: This page about SBT is very much a work in progress.

This page shows a sample Scala SBT build.sbt file, including the last line, which handles the SBT 're-run with -deprecation for details' warning message. (If you get the SBT 're-run with -deprecation' message, that last line hands the -deprecation option over to the compiler, so you can see the deprecation problems.)

name := "Test 1"

version := "1.0"

scalaVersion := "2.9.1"

resolvers += "Typesafe Repository" at ""

libraryDependencies += "com.typesafe.akka" % "akka-actor" % "2.0.2"

// for debugging sbt problems
logLevel := Level.Debug

scalacOptions += "-deprecation"

The page I linked to also shows this approach:

scalacOptions ++= Seq("-unchecked", "-deprecation")

Another sample SBT configuration file (build.sbt)

Here's another sample build.sbt SBT configuration file I use on a Scalatra and MongoDB (and Casbah) Scala project:

organization := "com.devdaily"

name := "ScalatraTest1"

version := "0.1.0-SNAPSHOT"

scalaVersion := "2.9.1"

seq(webSettings :_*)

libraryDependencies ++= Seq(
  "org.scalatra" %% "scalatra" % "2.0.4",
  "org.scalatra" %% "scalatra-scalate" % "2.0.4",
  "org.scalatra" %% "scalatra-specs2" % "2.0.4" % "test",
  "ch.qos.logback" % "logback-classic" % "1.0.0" % "runtime",
  "org.eclipse.jetty" % "jetty-webapp" % "7.6.0.v20120127" % "container",
  "javax.servlet" % "servlet-api" % "2.5" % "provided",
  "com.mongodb.casbah" %% "casbah" % "2.1.5-1"

resolvers += "Sonatype OSS Snapshots" at ""

A script to build an SBT project directory structure

On a related note, here's a shell script that creates an SBT project directory structure.

scalacOptions options

tpolecat has put together a nice description of scalacOptions options (flags) at this URL. They’re also available at this page.

Scala 3 scalacOptions examples

As a brief update, I just used these scalacOptions in a Scala 3 build.sbt file:

scalacOptions ++= Seq(
   "-deprecation",         // emit warning and location for usages of deprecated APIs
   "-explain",             // explain errors in more detail
   "-explain-types",       // explain type errors in more detail
   "-feature",             // emit warning and location for usages of features that should be imported explicitly
   "-indent",              // allow significant indentation.
   "-new-syntax",          // require `then` and `do` in control expressions.
   "-print-lines",         // show source code line numbers.
   "-unchecked",           // enable additional warnings where generated code depends on assumptions
   "-Ykind-projector",     // allow `*` as wildcard to be compatible with kind projector
   "-Xfatal-warnings",     // fail the compilation if there are any warnings
   "-Xmigration"           // warn about constructs whose behavior may have changed since version