Getting started with sbt

Download sbt eBook

Remarks

The Simple Build Tool (SBT for short) can be used to build Scala (or Java) project code. This includes managing code, dependencies, and resources that must be built, tested, and/or compiled to a .jar or other artifact. Custom tasks can be created to manage all of these processes.

A note on the name; SBT is sometimes referred to as the 'Scala Build Tool'. While this was not the original intent, it has come to be commonly used as well. SBT may be used to build any project on the JVM.

.sbt files, or 'SBT build definitions' are specially interpreted files, written in Scala, that are used by SBT to define a build. .scala build definitions may also be written and imported into an .sbt file.

Versions prior to 13.6 required that any .sbt file has each statement separated by a blank line. Without the blank line, the .sbt file will break.

A universal package exists in ZIP and TGZ formats.

Versions

VersionStateRelease Date
0.13.12Stable2016-07-17

Import SBT Project into Eclipse

This assumes you have installed both Eclipse and SBT.

  • Install the SBT plugin for Eclipse from the Eclipse marketplace.

  • In the command line switch directory to the root directory of the project.

    $ cd ~/home/sample/project

  • Execute sbt, which will load the project.

    $ sbt

  • Compile the project to ensure dependencies are obtainable.

    > compile

  • Run the eclipse task:

    > eclipse

  • Go into Eclipse and select the menu option:

    File > New > Project From Existing Sources

  • In the wizard, navigate to your project directory and select it. Eclipse will handle the rest.

Install on Mac OSX

Full official instructions can be found here.

MacPorts

Install MacPorts. Then, in the terminal execute:

port install sbt
 

Homebrew

Install Homebrew. Then, in the terminal execute:

brew install sbt
 

Sources

Download sbt All platforms (tgz) installation from SBT.

sudo su
cd /opt
mkdir sbt
cd sbt
curl https://dl.bintray.com/sbt/native-packages/sbt/0.13.13/sbt-0.13.13.tgz -o sbt-0.13.13.tgz
 

Then, execute following

tar zxf sbt-0.13.13.tgz
ln -s sbt-0.13.13 latest
 

Inside your $HOME make sure to update ~/.profile - by adding following lines

export SBT_HOME=/opt/sbt/latest
export PATH=$PATH:$SBT_HOME/bin
 

Verification

In the terminal execute:

which sbt
 

You should expect output similar to:

/opt/local/bin/sbt
 

If you get no output sbt is not installed.

Install SBT on Linux

Full instructions can be found here.

  1. Install the JDK.

  2. Set the Java Environment variable.

    export JAVA_HOME=/usr/local/java/jdk1.8.0_102
    echo $JAVA_HOME
    /usr/local/java/jdk1.8.0_102
    export PATH=$PATH:$JAVA_HOME/bin/
    echo $PATH
    ...:/usr/local/java/jdk1.8.0_102/bin/
     
  3. Install Scala.

    sudo wget http://www.scala-lang.org/files/archive/scala-2.11.8.deb
    sudo dpkg -i scala-2.11.8.deb
    sudo apt-get update
    sudo apt-get install scala
     
  4. Install SBT.

    wget https://bintray.com/artifact/download/sbt/debian/sbt-0.13.9.deb
    sudo dpkg -i sbt-0.13.9.deb
    sudo apt-get update
    sudo apt-get install sbt
     

RPM-based Linux Distributions

  • Download SBT repository definitions and add it to YUM:

    curl https://bintray.com/sbt/rpm/rpm | sudo tee /etc/yum.repos.d/bintray-sbt-rpm.repo
     
  • Install SBT according to the definitions previously added to YUM:

    sudo yum install sbt
     

Install SBT on Windows

Install

MSI installers can be found here. This is the latest stable version. Download and execute to install.

Verify Installation

  • Use the WindowsKey + R , type cmd .

  • Alternatively, navigate to the .sbt (for example, in C:\Users\Hopper ) and type cmd in the address bar.

  • Type sbt about to get version information, verifying it is installed. You should see something like this:

    Java HotSpot(TM) 64-But Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
    [info] Set current project to root--sbt (in build file:/C:/Users/Hopper/.sbt/)
    [info] This is sbt 0.13.8
    ...
     

Stats

149 Contributors: 10
Saturday, January 7, 2017
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook