sbt provides both an interactive shell and batch mode execution. This page documents available commands, command-line options, and usage patterns.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.
Running sbt
Interactive Mode
Start the sbt shell for interactive command execution:Batch Mode
Execute commands and exit:Use quotes around commands with arguments to prevent shell interpretation.
Common Commands
Compilation Commands
Compiles main sources in the current project.
Deletes all generated files (target directory).
Reloads the build definition after changes to
build.sbt or project/ files.Running Applications
Runs the main class for the current project.
Runs a specific main class.
Testing Commands
Runs all tests (or incrementally runs tests that failed or changed).
Runs specific test classes or suites.
Runs tests that failed in previous runs or whose dependencies changed.
Interactive Commands
Starts the Scala REPL with the project classpath.Type
:quit or press Ctrl+D to exit the console.Starts the Scala REPL with dependencies but without compiling project sources.
Starts the Scala REPL with the sbt build definition on the classpath.Useful for debugging build definitions.
Package Commands
Creates a JAR file containing compiled classes and resources.Output:
target/scala-<version>/<name>_<scalaVersion>-<version>.jarCreates a JAR file containing source files.
Creates a JAR file containing API documentation.
Documentation Commands
Generates API documentation using Scaladoc.Output:
target/scala-<version>/api/Dependency Commands
Resolves and downloads dependencies.Usually not needed as it runs automatically when required.
Shows the dependency tree (requires sbt-dependency-graph plugin).
Shows eviction warnings for conflicting dependencies.
Command Prefixes
Configuration Scoping
Prefix commands with a configuration:Project Scoping
For multi-project builds, scope commands to a specific project:Combined Scoping
Combine project and configuration scopes:Command Composition
Sequential Execution
Run multiple commands in sequence using semicolons:Continuous Execution
Prefix a command with~ for continuous/triggered execution:
Multiple Projects
Useall to run a command on all projects:
sbt Launcher Options
Command-line options for the sbt launcher:Memory Options
The
-J prefix passes options directly to the JVM.System Properties
sbt Options
Enable verbose output.
Enable debug logging.
Display help information.
Display sbt version.
Disable ANSI color codes in output.
Force client mode (connect to existing server).
Force batch mode (no interactive shell).
Configuration Files
Override global sbt directory (default:
~/.sbt).Override Ivy home directory (default:
~/.ivy2).Shell Commands
Project Navigation
List all projects in the build.
Switch to a different project or display the current project.
Inspecting Settings
Display the value of a setting or task result.
Display detailed information about a setting or task.
Session Management
Save temporary settings to
build.sbt.Clear all session settings.
Setting Values Temporarily
Set a value for the current session.Changes are lost when exiting sbt unless saved with
session save.Help Commands
Display help for commands.
List available tasks.
List available settings.
Environment Variables
JVM options for sbt.
Additional JVM options (merged with SBT_OPTS).
Java installation directory.
Common Workflows
Development Workflow
Clean Build
Multi-Project Workflow
Release Workflow
Best Practices
1. Use Interactive Shell for Development
2. Use Batch Mode for CI/CD
3. Quote Commands with Arguments
4. Use .sbtopts for Project-Specific Options
Create a.sbtopts file in the project root:
5. Use Continuous Execution
Exit Codes
sbt returns exit codes for scripting:| Exit Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Error (compilation failure, test failure, etc.) |
| 130 | Interrupted (Ctrl+C) |
See Also
- Settings and Tasks - Understanding what commands execute
- Configurations - Scoping commands to configurations
- Directory Structure - Understanding project layout