0Pricing
Scala for Backend Engineering & Functional Programming · Lesson

SBT Project Setup and Basics

Learn to initialize new SBT projects, define settings, and execute common build tasks.

SBT Project Setup and Basics is a free Scala for Backend Engineering & Functional Programming lesson on CoddyKit — lesson 1 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Scala for Backend Engineering & Functional Programming learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Welcome to SBT!

Hello! Today we're diving into SBT, the standard build tool for Scala projects. Think of it as your project's manager, handling everything from compiling code to running tests and packaging your application.

SBT stands for Scala Build Tool. It simplifies complex tasks and ensures your projects are set up correctly.

Why Use SBT?

SBT brings several benefits to Scala development:

  • Dependency Management: Easily add external libraries your project needs.
  • Project Structure: Enforces a standard layout, making projects easy to navigate.
  • Task Automation: Automate compilation, testing, packaging, and more with simple commands.
  • Consistency: Ensures everyone on a team builds and runs the project in the same way.

Getting SBT Installed

Before we can use SBT, we need to install it. The recommended way is often through a package manager like Coursier or Homebrew (on macOS/Linux) or by downloading the official launcher.

Once installed, you can verify it by checking the version in your terminal:

sbt --version

Creating a New Project

SBT provides a convenient way to create new projects using templates. We'll use the sbt new command with a basic Scala seed template.

This command will set up the necessary directories and files for a simple Scala application:

sbt new scala/scala-seed.g8 --name my-first-sbt-app

Exploring Project Structure

After creating my-first-sbt-app, you'll see a standard directory structure:

  • src/main/scala/: Your main Scala source code goes here.
  • src/test/scala/: For your test files.
  • project/: Contains project-specific SBT configurations.
  • build.sbt: The main configuration file for your project.

The build.sbt file is where you define project settings.

Basic build.sbt Configuration

The build.sbt file uses a simple syntax to define project settings. Here's a basic example:

  • name := "my-first-sbt-app": Sets your project's name.
  • version := "0.1.0-SNAPSHOT": Defines the project's version.
  • scalaVersion := "2.13.12": Specifies the Scala version to use.

These are key-value pairs where := assigns a value to a setting.

name := "my-first-sbt-app"
version := "0.1.0-SNAPSHOT"
scalaVersion := "2.13.12"

Your First Scala Program

Let's add a simple Scala program to our project. Inside src/main/scala/, create a file named Main.scala. This program will just print a greeting.

SBT will automatically find and compile this file when you run commands like compile or run.

object Main {
  def main(args: Array[String]): Unit = {
    println("Hello from SBT!")
  }
}

Running Your Application

With your Main.scala file in place, navigate to your project's root directory in the terminal (e.g., cd my-first-sbt-app).

You can then use the sbt run command. SBT will compile your code and execute the main method it finds.

sbt run

The SBT Interactive Shell

You can also enter the SBT interactive shell by just typing sbt in your project's root directory. This keeps SBT running, making subsequent commands faster.

Inside the shell, you can type commands like compile, run, or test directly. Type exit to leave the shell.

sbt

> compile
> run
> exit

Quick Check: SBT Basics

Which of the following settings is typically used in build.sbt to specify the Scala version for your project?

SBT Journey Continues!

Great job! You've taken your first steps with SBT.

We covered:

  • What SBT is and why it's essential.
  • How to set up a new SBT project.
  • Understanding the basic project structure.
  • Configuring fundamental settings in build.sbt.
  • Running your first Scala application using SBT commands.

Next, we'll explore how to manage external libraries and use SBT plugins to extend your project's capabilities!

Frequently asked questions

Is the “SBT Project Setup and Basics” lesson free?

Yes — the full text of “SBT Project Setup and Basics” is free to read here on the web, and the Scala for Backend Engineering & Functional Programming course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Scala for Backend Engineering & Functional Programming course, upgrade to CoddyKit PRO.

What will I learn in “SBT Project Setup and Basics”?

Learn to initialize new SBT projects, define settings, and execute common build tasks. You practise Scala for Backend Engineering & Functional Programming with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Scala for Backend Engineering & Functional Programming?

No prior experience is required. Scala for Backend Engineering & Functional Programming on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 3, so you can start here or from the beginning and move at your own pace.

How long does the “SBT Project Setup and Basics” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Scala for Backend Engineering & Functional Programming lesson?

Yes. Every Scala for Backend Engineering & Functional Programming lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. SBT Project Setup and Basics
  2. Dependency Management and Plugins
  3. Multi-Project Builds and Deployment
← Back to Scala for Backend Engineering & Functional Programming