...

/

What Is the Scala Build Tool?

What Is the Scala Build Tool?

Learn how to create and structure an sbt-based project.

What is sbt?

The Scala Build Tool (sbt) is a general-purpose building tool, written in Scala, that provides many convenient Scala features. In this lesson, we’ll cover many general aspects of sbt along with the basic layout of an sbt project. We’ll see how our testing project is structured and dive deeper into some interesting sbt settings.

Once sbt is set up, we can either create a new project from scratch or benefit from a Giter8 template. Giter8 is a command line tool that quickly generates files and directories. Although written in Scala and run through sbt, Giter8 can produce any files and directories, not only Scala projects. It bases generation on templates published in any git repository. For example, we can quickly generate a basic Scala project by running the following command:

$ sbt new scala/scala-seed.g8
[info] Loading global plugins from /home/matteo/.sbt/1.0/plugins
[info] Set current project to test (in build file:/home/matteo/projects/)
[info] Set current project to test (in build file:/home/matteo/projects/)
A minimal Scala project.
name [Scala Seed Project]: TestProject
Template applied in /home/matteo/projects/./testproject
Example of creating a new sbt project via Giter8

Folder organization

The command above will produce the following files and directories:

.
├── build.sbt
├── project
│   ├── build.properties
│   └── Dependencies.scala
└── src
├── main
│   └── scala
│   └── example
│   └── Hello.scala
└── test
└── scala
└── example
└── HelloSpec.scala
Folder structure of a basic sbt project

In this structure:

  • build.sbt is a plain Scala file, laced at the root of the project. Here, we can specify the basic attributes (such as the name and version of the project), the version of Scala, and the dependencies.

  • project contains the project definition files. The ...