Mar 12, 2014

Introduction to SBT (Scala Build Tool)

SBT is abbreviation for Scala Build Tool. This tool is a great help if you are a newbie in Scala like me. Its simple yet very powerful as far as Scala projects are concerned. In this tutorial we will see
  • How to create a small project (first without any dependency and later with dependency on some external jar files)
  • How to compile our code with sbt tool
  • How to run this code with sbt
  • What will be folder structure of our say decently complex project and how to segregate our main code and our test cases code.

So first lets start with installation of this tool. This tool can be downloaded from here. Once you download the tool extract the zip file on your local machine and set environment variable SBT_HOME to location where the file is extracted. Also add %SBT_HOME%/bin in your path so that you can run sbt command from anywhere you want.

Now go to directory where you want to write and run your Scala code and create a file HelloWorld.scala in this folder as follows


Once this file is created, open DOS shell and go to this folder and execute following command. 

sbt run

This command will not require any build file. It will automatically compile as well as run the HelloWorld.scala as shown in image below.




So now we know about basic sbt command so now we can look at few more commands and bit complicated code that will require some third party jar that sbt will try to download from maven/ivy repository.