TheDocumentation 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.
SemanticdbPlugin automatically enables SemanticDB generation for Scala projects. SemanticDB is a data model for semantic information about programs in Scala and other languages, used by tools like Metals (Scala LSP server), Scalafix, and other code analysis tools.
Activation
This plugin is automatically enabled on all projects that haveJvmPlugin enabled (which is most Scala/Java projects):
Key Settings
semanticdbEnabled
Enables or disables SemanticDB generation. Can be controlled via system property.
semanticdbVersion
Version of the SemanticDB compiler plugin to use. Default:
"4.14.2"semanticdbIncludeInJar
Whether to include SemanticDB files in the compiled JAR. Default:
falsesemanticdbOptions
Additional compiler options for SemanticDB generation.
semanticdbTargetRoot
Target directory for SemanticDB files. Automatically configured based on
semanticdbIncludeInJar.How It Works
The plugin automatically:- Adds the SemanticDB compiler plugin as a dependency (for Scala 2.x)
- Configures compiler options based on Scala version:
- Scala 2.x:
-Yrangeposand-P:semanticdb:targetroot:... - Scala 3.0.0-M1/M2:
-Ysemanticdb - Scala 3.x:
-Xsemanticdb
- Scala 2.x:
- Manages target directories for generated SemanticDB files
- Integrates with incremental compilation to cache SemanticDB generation
Scala Version Compatibility
The plugin handles different Scala versions automatically:Configuration Examples
Enable SemanticDB globally
In your global sbt settings (~/.sbt/1.0/global.sbt):
Enable for specific project
Inbuild.sbt:
Include SemanticDB in JAR
If you want to ship SemanticDB files with your library:Custom SemanticDB version
IDE Integration
SemanticDB is automatically used by:- Metals: The Scala language server for VS Code, Vim, Emacs, and other editors
- IntelliJ IDEA: For enhanced code analysis
- Scalafix: For code linting and refactoring
When using Metals or other LSP servers, they will automatically enable
semanticdbEnabled as needed. You typically don’t need to manually configure this setting.Troubleshooting
SemanticDB files not generated
Check that:semanticdbEnabled := trueis set- Your Scala version is supported
- The compiler plugin is being added (check
show allDependencies)
IDE not finding definitions
Ensure:- SemanticDB is enabled for all configurations you’re working in (Compile and Test)
- You’ve run
compileorTest/compileafter enabling SemanticDB - Your IDE is pointing to the correct SemanticDB output directory
Performance Considerations
Source Reference
Implemented inSemanticdbPlugin.scala:
- Location:
main/src/main/scala/sbt/plugins/SemanticdbPlugin.scala - Lines 24-100+
Related
- JvmPlugin - Required by SemanticdbPlugin
- Incremental Compilation - How SemanticDB integrates with Zinc