Documentation Index
Fetch the complete documentation index at: https://mintlify.com/sbt/sbt/llms.txt
Use this file to discover all available pages before exploring further.
Quick Start Guide
This guide will walk you through creating your first sbt project and introduce you to the essential commands and concepts.Make sure you have installed sbt before continuing.
Create Your First Project
Let’s create a simple “Hello World” Scala application.Create the build definition
Create a file named This minimal build file tells sbt:
build.sbt in the project root:build.sbt
- Your project’s name is “hello-world”
- The version is “0.1.0”
- You’re using Scala 3.8.2
Create your source file
Create the source directory structure and your first Scala file:Create This uses Scala 3’s
src/main/scala/Main.scala:src/main/scala/Main.scala
@main annotation to create an entry point.Start the sbt shell
Launch sbt’s interactive shell:The first time you run sbt, it will:
- Download the sbt launcher and dependencies (this may take a minute)
- Load your project
- Present you with the sbt prompt:
sbt:hello-world>
The sbt shell keeps your project loaded in memory, making subsequent commands much faster than running
sbt separately each time.Compile your project
At the sbt prompt, compile your code:You’ll see output like:Your compiled classes are now in
target/scala-3.8.2/classes/.Understanding the Project Structure
Your project now looks like this:Essential sbt Commands
Here are the most common commands you’ll use in the sbt shell:You can run these commands from the sbt shell (recommended) or as one-off commands like
sbt compile from your terminal.Continuous Build
One of sbt’s most powerful features is watching for file changes:~ prefix tells sbt to watch for changes and automatically re-execute the command. Press Enter to stop watching.
Adding Dependencies
Let’s add a library dependency to your project. Update yourbuild.sbt:
build.sbt
%% operator automatically adds the Scala version suffix (e.g., cats-core_3).
After saving, reload sbt:
Adding Test Dependencies
To add a testing library like ScalaTest:build.sbt
% Test scope means this dependency is only available for test code.
Working with Tests
Let’s add a test to your project.Interactive Shell Features
The sbt shell has several productivity features:Tab Completion
Press Tab to see available commands or complete partial commands:Command History
Use Up/Down arrows to navigate command history, just like in your shell.Multi-Command Execution
Run multiple commands separated by semicolons:Command Aliases
Define shortcuts in yourbuild.sbt:
build.sbt
testc instead of typing clean ; test.
Specifying the sbt Version
Createproject/build.properties to specify which sbt version your project uses:
project/build.properties
Next Steps: Java Example
Sbt works great with Java too! Here’s a quick Java example:Common Patterns
Setting Java Version
To specify Java compiler version:build.sbt
Running with Arguments
Pass arguments to your application:Forking the JVM
Run your application in a separate JVM:build.sbt
Setting JVM Options
build.sbt
Troubleshooting
Compilation Errors
If you see compilation errors:- Check that your Scala version matches your code (Scala 2 vs Scala 3 syntax differs)
- Make sure source files are in the correct directory (
src/main/scala/) - Verify dependencies are correctly specified in
build.sbt
Dependency Resolution Issues
If dependencies fail to download:Out of Memory
If you get OutOfMemory errors:Reload After Changes
Always reload after editingbuild.sbt:
Learning More
Now that you’ve created your first project, dive deeper:Build Definition
Learn about settings, tasks, scopes, and how to structure complex builds
Dependency Management
Master library dependencies, resolvers, and managing transitive dependencies
Multi-Project Builds
Organize large codebases with multiple subprojects and shared settings
Plugins
Extend sbt with plugins for testing, packaging, deployment and more
Quick Reference
Summary
You’ve learned:- ✅ How to create a new sbt project from scratch
- ✅ The standard project structure (
src/main/scala,build.sbt) - ✅ Essential commands:
compile,run,test,reload - ✅ How to add dependencies to your project
- ✅ Continuous build with the
~prefix - ✅ Working with the interactive shell
- ✅ Both Scala and Java project setup