Configurations in sbt are a way to organize and scope settings, tasks, and dependencies. They’re similar to Maven scopes but more flexible.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.
What Are Configurations?
A configuration is a named grouping of settings and dependencies. Each configuration can:- Define its own set of source directories
- Have separate classpaths
- Extend other configurations to inherit their settings
- Be public (visible to downstream projects) or private
Built-in Configurations
sbt provides several predefined configurations based on Maven conventions:Compile
The main configuration for production code and dependencies.Characteristics:
- Sources:
src/main/scala,src/main/java - Resources:
src/main/resources - Classes output:
target/scala-<version>/classes - Public: Yes
- Extends: None
Test
Configuration for test code and test-only dependencies.Characteristics:
- Sources:
src/test/scala,src/test/java - Resources:
src/test/resources - Classes output:
target/scala-<version>/test-classes - Public: No
- Extends:
Runtime(includes all compile and runtime dependencies)
Runtime
Dependencies needed at runtime but not for compilation.Characteristics:
- No dedicated source directories
- Public: Yes
- Extends:
Compile - Transitive: Yes
Provided
Dependencies provided by the runtime environment (like servlet APIs provided by a container).Characteristics:
- Available for compilation
- Not included in packaged artifacts
- Public: Yes
- Extends: None
- Transitive: Yes
Optional
Optional dependencies that consumers can choose to include.Characteristics:
- Public: Yes
- Extends: None
- Transitive: Yes
Configuration Hierarchy
Configurations can extend other configurations, creating an inheritance hierarchy:Runtimehas access to allCompiledependencies and settingsTesthas access to allRuntimeandCompiledependencies and settings
Scoping to Configurations
Syntax
Use the/ operator to scope settings and tasks to a configuration:
Common Configuration-Scoped Settings
IntegrationTest Configuration
For integration tests, you can define a custom configuration:Custom Configurations
You can create custom configurations for specialized needs:Custom configuration names should start with an uppercase letter by convention.
Internal Configurations
sbt maintains internal configurations for managing classpaths:| Configuration | Purpose |
|---|---|
CompileInternal | Internal classpath for Compile including optional and provided dependencies |
RuntimeInternal | Internal classpath for Runtime including optional dependencies |
TestInternal | Internal classpath for Test including all dependencies |
Special Configurations
CompilerPlugin
Configuration for Scala compiler plugins.
ScalaTool, ScalaDocTool, ScalaReplTool
Hidden configurations used internally for Scala infrastructure:ScalaTool: Scala compiler and libraryScalaDocTool: Scaladoc generatorScalaReplTool: Scala REPL
Configuration Best Practices
1. Use Standard Configurations
Stick to standard configurations (Compile, Test, Runtime, Provided) when possible:
2. Scope Settings Appropriately
3. Extend Configurations Carefully
When creating custom configurations, extend the appropriate base:4. Use inConfig for Configuration Settings
Configuration Classpath
Each configuration maintains its own classpath:Dependency Configuration Mapping
You can map configurations when declaring dependencies:See Also
- Settings and Tasks - Working with scoped settings
- Directory Structure - Configuration source directories
- Command Line - Running tasks in specific configurations