Skip to main content

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.

sbt is built as a collection of highly modular components organized into separate projects. This modular architecture allows each component to evolve independently while maintaining clean boundaries between different concerns.

Core Architecture Principles

sbt 2.x is split across multiple GitHub repositories: The main sbt repository contains numerous submodules that implement different aspects of the build system.

Main Modules

Core Modules

The central module that brings together all components. Located in main/, it contains:
  • Keys.scala - Defines all built-in setting and task keys
  • Defaults.scala - Default implementations of built-in tasks
  • Main.scala - Entry point and main loop
  • Build definitions and project loading
  • Internal implementation in sbt/internal/
Key files: main/src/main/scala/sbt/
The task execution engine that powers sbt’s parallel task execution. Located in tasks/.Core components:
  • Execute.scala - Task graph execution
  • ConcurrentRestrictions.scala - Parallel execution controls
  • CompletionService.scala - Async task completion
  • Result.scala - Task result types
This module provides the foundation for sbt’s task system, including dependency tracking and concurrent execution.
Settings system implementation in main-settings/. Handles:
  • Setting initialization and composition
  • Scope resolution
  • Setting delegation
Settings are computed once at build load time, while tasks are executed on demand.
Command-line interface and command processing in main-command/. Provides:
  • Command parsing
  • Built-in commands
  • Tab completion infrastructure
  • Interactive shell
High-level build actions in main-actions/. Implements:
  • Compilation actions
  • Test execution
  • Publishing
  • Other common build operations

Protocol and Communication

Data type definitions and communication protocols in protocol/.Uses Contraband to define:
  • Build Server Protocol (BSP) types in sbt.internal.bsp
  • Internal protocol messages
  • JSON serialization formats
Contraband generates pseudo case classes that maintain binary compatibility across versions.Key directory: protocol/src/main/contraband-scala/sbt/internal/bsp/

Internal Utilities

The internal/ directory contains utility modules:
ModulePurposeLocation
util-coreCore utilities and basic abstractionsinternal/util-core
util-loggingLogging infrastructure with multiple appendersinternal/util-logging
util-controlControl flow utilitiesinternal/util-control
util-completeTab completion implementationinternal/util-complete
util-cacheCaching utilitiesutil-cache
util-trackingFile change trackingutil-tracking
util-positionSource position trackinginternal/util-position
util-relationRelational data structuresinternal/util-relation
util-logicLogic programming utilitiesinternal/util-logic
util-scriptedScripted test frameworkinternal/util-scripted

Library Management

sbt uses Coursier (since sbt 1.3) for dependency resolution and artifact retrieval:
  • lm-core - Core library management abstractions
  • lm-coursier - Coursier integration
  • lm-ivy - Legacy Apache Ivy support
Coursier provides faster, more reliable dependency resolution compared to the older Ivy-based system.

Zinc Integration

Bridges Zinc incremental compiler with library management in zinc-lm-integration/.Key components:
  • ZincComponentCompiler.scala - Compiles compiler bridges
  • ZincComponentManager.scala - Manages Zinc components
  • ZincLmUtil.scala - Utility functions
This module handles:
  • Compiler bridge compilation and caching
  • Scala instance creation
  • Component resolution through library management
See Zinc Incremental Compiler for details.

Testing

Test framework integration in testing/. Provides:
  • Test framework discovery
  • Test execution infrastructure
  • Integration with JUnit, ScalaTest, specs2, etc.
Scripted testing framework for sbt plugins in scripted-sbt/.Allows plugin authors to write integration tests that:
  • Set up test projects
  • Run sbt commands
  • Verify expected outcomes

Other Modules

ModulePurpose
runForked process execution for run tasks
workerWorker process for isolated task execution
core-macrosMacro definitions used by sbt
sbt-remote-cacheRemote build cache support
buildfileBuild file definitions
clientClient-server communication
sbt-appApplication packaging
launcher-packagesbt launcher

Technology Stack

sbt uses several specialized libraries:
  • Contraband - Type-safe data definitions with binary compatibility
  • sjson-new - JSON serialization with pluggable backends
  • Coursier - Modern dependency resolution
  • Gigahorse - HTTP client for remote operations
  • Zinc - Incremental Scala compilation

Module Dependencies

The module dependency structure flows roughly as:
internal/util-* (utilities)

tasks (execution engine)

main-settings, main-command, main-actions

main (orchestration)

sbt-app (application)
Binary Compatibility: sbt must maintain backward binary compatibility across minor releases. When contributing, always run mimaReportBinaryIssues to verify compatibility.

Source Code Organization

Each module typically follows this structure:
  • src/main/scala/ - Main Scala source code
  • src/main/scala/sbt/ - Public API
  • src/main/scala/sbt/internal/ - Internal implementation
  • src/test/scala/ - Unit tests
  • src/main/contraband-scala/ - Generated code from Contraband (protocol module)

Next Steps

Zinc Compiler

Learn about sbt’s incremental compilation engine

Build Server Protocol

Understand BSP integration in sbt

Contributing

Guidelines for contributing to sbt

Tech Stack

Deep dive into libraries and tooling