Scala SBT

SBT (Simple Build Tool)

– It is a build tool for Scala projects
– Just like Ant and Maven for Java Projects
– Used to handle both Managed and Unmanaged dependencies

File: build.sbt

– Used to define project dependencies and other project settings
– Settings are specified using key value pairs
– It’s not needed for very simple projects

SBT Commands

SBT Version:

$ sbt version -> Gives the Project Version
$ sbt sbt-version -> Gives the SBT Version
$ sbt sbtVersion -> Gives the SBT Version (Windows only)
$ sbt about -> Gives the SBT, Scala and Plugin info

Create Directories:

[Refer: Shell script from GitHub Gist -> ->]
$ sbtmkdirs
Project Name: HelloWorld

Alternate Approach:

$ mkdir HelloWorld
$ cd HelloWorld
$ mkdir -p src/main/java
$ mkdir -p src/main/scala
$ mkdir -p src/main/resources
$ mkdir -p src/test/java
$ mkdir -p src/test/scala
$ mkdir -p src/test/resources
$ tree
$ rm -R HelloWorld

C:\> mkdir HelloWorld
C:\> cd HelloWorld
C:\> mkdir src\main\java
C:\> mkdir src\main\scala
C:\> mkdir src\main\resources
C:\> mkdir src\test\java
C:\> mkdir src\test\scala
C:\> mkdir src\test\
C:\> tree
C:\> rmdir /S HelloWorld

View Directory Structure:

$ cd HelloWorld
$ tree

Compile Application:

$ sbt compile

Run Application:

$ sbt run

Create JAR file:

$ sbt package

Run the Scala Jar:

$ scala target/scala-2.10/helloworld_2.10-1.0.jar

SBT Shell:

$ cd HelloWorld
$ sbt
> run
> exit

$ sbt
> update
> console
scala> // REPL
scala> sys.exit
> exit

Several Commands:

$ sbt clean run

Create Uber JAR file:

$ sbt assembly



name := “HelloWorld”

version := “1.0”

scalaVersion := “2.10.3”

resolvers ++= Seq(
“Typesafe Repository” at “”,
“oracle driver repo” at “”

libraryDependencies ++= Seq(
“com.typesafe.akka” %% “akka-actor” % “2.1.2”,
“com.typesafe” % “config” % “1.2.1”

scalacOptions += “-deprecation”

unmanagedJars in Compile += file(“lib/ojdbc6-”)

mainClass in assembly := some(“”)
assemblyJarName := “nag_arvind_gudiseva.jar”

val meta = “””META.INF(.)*”””.r
assemblyMergeStrategy in assembly := {
case PathList(“javax”, “servlet”, xs @ _*) => MergeStrategy.first
case PathList(ps @ _*) if ps.last endsWith “.html” => MergeStrategy.first
case n if n.startsWith(“reference.conf”) => MergeStrategy.concat
case n if n.endsWith(“.conf”) => MergeStrategy.concat
case meta(_) => MergeStrategy.discard
case x => MergeStrategy.first

// put all libs in the lib_managed directory, that way we can distribute eclipse project files
retrieveManaged := true


Object HelloWorld extends App {
println(“Hello, World!”)


logLevel := Level.Warn
addSbtPlugin(“com.eed3si9n” % “sbt-assembly” % “0.12.0”)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.