Wednesday, February 12, 2014

An introduction to SBT


http://www.adelbertc.com/posts/2014-01-21-basic-sbt.html

SBT Basics

Adelbert Chang - 21 January 2014
I’ve talked with a sufficient number of people who want to get into Scala but are lost as to how to get a simple SBT project started, so I figured I’d put up a quick guide.

Installation

On Mac OS I personally just use the Homebrew package manager, and run brew install sbt.
Alternatively, I know some people like to do manual installation, which I had done myself before I started using Homebrew.
To check to make sure your installation was successful, type in sbt --version at the prompt.

A note about SBT and Scala

You do NOT need Scala/scalac installed to run SBT - while SBT is written in Scala, it has already been shoved into a JAR and depends only on an installation of Java. I still recommend having Scala installed so you have access to the REPL, but the two can be considered as disjoint installations.

Directory structure

For simple projects, you should make a folder dedicated to your project. The directory structure should look something like this:
myproject/
    build.sbt
    project/
        build.properties
    src/
        main/
            scala/
                mypackage/

build.sbt

build.sbt will be where the majority of your SBT configuration will be. Below is an example of a simple build.sbt file:
name := "myproject"

scalaVersion := 2.10.3

scalacOptions ++= Seq(
  "-deprecation", 
  "-encoding", "UTF-8",
  "-feature", 
  "-unchecked"
)

resolvers ++= Seq(
  "Sonatype OSS Releases"  at "http://oss.sonatype.org/content/repositories/releases/",
  "Sonatype OSS Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
)

libraryDependencies ++= Seq(
  "org.scalaz"  %% "scalaz-core"      % "7.0.5",
  "com.chuusai" %  "shapeless_2.10.2" % "2.0.0-M1"
)

No comments: