Manage SBT dependencies from a single YAML file with version markers, auto-updates, and cross-project support
Add the following line to your project/project/plugins.sbt file:
addSbtPlugin("com.alejandrohdezma" % "sbt-dependencies" % "0.9.0")Adding the plugin to
project/project/plugins.sbt(meta-build) allows it to manage both your build dependencies and your project dependencies.
Create a project/dependencies.conf file listing your dependencies:
sbt-build = [
"ch.epfl.scala:sbt-scalafix:0.14.5:sbt-plugin"
"org.scalameta:sbt-scalafmt:2.5.4:sbt-plugin"
"io.get-coursier::coursier:2.1.24"
]
my-project = [
"org.typelevel::cats-core:2.10.0"
"org.scalameta::munit:1.2.1:test"
]Groups correspond to:
sbt-build: Dependencies for your build definition (plugins and libraries used inbuild.sbt)<project-name>: Dependencies for a specific project (matches the SBT project name)
The plugin automatically populates libraryDependencies for each project based on its group.
Tip: Run
initDependenciesFileto automatically generate this file from your existinglibraryDependenciesandaddSbtPluginsettings.
Dependencies follow this format:
org::name:version:config # Cross-compiled (Scala) dependency with configuration
org::name:version # Cross-compiled (Scala) dependency
org::name # Cross-compiled, latest version resolved automatically
org:name:version:config # Java dependency with configuration
org:name:version # Java dependency
org:name # Java, latest version resolved automatically
Supported configurations: compile (default), test, provided, sbt-plugin, etc.
Dependencies with Scala version suffixes in their artifact name are automatically filtered based on the current scalaVersion:
my-project = [
"org.example:my-lib_2.13:1.0.0" # Only added when scalaVersion is 2.13.x
"org.example:my-lib_2.12:1.0.0" # Only added when scalaVersion is 2.12.x
"org.example:my-lib_3:1.0.0" # Only added when scalaVersion is 3.x
"org.example:other-lib:1.0.0" # Always added (no suffix)
]This is useful for dependencies that are published with Scala-specific variants but aren't cross-compiled in the usual way (e.g., some native libraries or Java libraries with Scala-specific modules).
Control how dependencies are updated using version markers:
| Marker | Example | Behavior |
|---|---|---|
| (none) | 2.10.0 |
Update to latest compatible version |
= |
=2.10.0 |
Pin to exact version, never update |
^ |
^2.10.0 |
Update within major version only (2.x.x) |
~ |
~2.10.0 |
Update within minor version only (2.10.x) |
You can use variable syntax to reference versions defined (or computed) in your build:
my-project = [
"org.typelevel::cats-core:{{catsVersion}}"
"org.typelevel::cats-effect:{{catsVersion}}"
]Define variable resolvers in your build.sbt:
dependencyVersionVariables := Map(
"catsVersion" -> { artifact => artifact % "2.10.0" }
)When running updateDependencies, variable-based dependencies show their resolved version and the latest available version, but the variable reference is preserved in the file.
Groups support an advanced format that enables additional configuration beyond just listing dependencies:
my-project {
scala-versions = ["2.13.12", "2.12.18", "3.3.1"]
dependencies = [
"org.typelevel::cats-core:2.10.0"
"org.scalameta::munit:1.2.1:test"
]
}The simple format (array of dependencies) and advanced format (object with dependencies key) can be mixed in the same file.
You can configure scalaVersion and crossScalaVersions directly in dependencies.conf using the advanced format:
sbt-build {
scala-versions = ["2.13.12", "2.12.18"]
dependencies = [
"ch.epfl.scala:sbt-scalafix:0.14.5:sbt-plugin"
]
}
my-project {
scala-version = "3.3.1"
dependencies = [
"org.typelevel::cats-core:2.10.0"
]
}Use scala-version (singular) for a single version or scala-versions (plural) for cross-building.
Behavior:
- The first version becomes
scalaVersion - All versions become
crossScalaVersions scala-version/scala-versionsin thesbt-buildgroup applies at the build level (ThisBuild / scalaVersionandThisBuild / crossScalaVersions)scala-version/scala-versionsin individual project groups overrides the build-level settings for that project
This allows you to set a default Scala version for all projects while letting specific projects use different versions.
Example: Using with here-sbt-bom
The here-sbt-bom plugin reads Maven BOM files and exposes version constants. You can reference these in your dependencies.conf:
my-project = [
"com.fasterxml.jackson.core:jackson-core:{{jackson}}"
"com.fasterxml.jackson.core:jackson-databind:{{jackson}}"
]// build.sbt
val jacksonBom = Bom("com.fasterxml.jackson" % "jackson-bom" % "2.14.2")
dependencyVersionVariables := Map(
"jackson" -> { artifact => artifact % jacksonBom.key.value }
)Creates (or recreates) the dependencies.conf file based on your current libraryDependencies and addSbtPlugin settings. This is useful when migrating an existing project to use this plugin.
sbt> initDependenciesFileAfter running this command, remember to remove the libraryDependencies += and addSbtPlugin lines from your build files, as the plugin will now manage them via dependencies.conf.
Displays the library dependencies for the current project in a formatted, colored output. Shows both direct dependencies and those inherited from dependent projects (via .dependsOn).
sbt> showLibraryDependencies- Green = direct dependencies
- Yellow = inherited from other projects
Updates dependencies in the current project to their latest versions.
sbt> updateDependencies # Update all project dependencies
sbt> updateDependencies org.typelevel: # Update all `org.typelevel` dependencies
sbt> updateDependencies :cats-core # Update `cats-core` from any organization
sbt> updateDependencies org.typelevel:cats-core # Update specific dependencyInstalls a new dependency to the current project.
sbt> install org.typelevel::cats-core:2.10.0
sbt> install org.typelevel::cats-effect # Resolves latest version
sbt> install org.scalameta::munit:1.2.1:testUpdates dependencies in the meta-build (project/dependencies.conf, group sbt-build).
sbt> updateBuildDependenciesInstalls a new dependency to the meta-build.
sbt> installBuildDependencies ch.epfl.scala:sbt-scalafix:0.14.5:sbt-pluginUpdates everything: the plugin itself, Scala versions, dependencies, and SBT version.
sbt> updateAllDependenciesUpdates the sbt-dependencies plugin itself in project/project/plugins.sbt.
sbt> updateSbtDependenciesPluginUpdates the SBT version in project/build.properties to the latest version. If updated, triggers a reboot to apply the new version.
sbt> updateSbtUpdates Scala versions in the current project to their latest versions within the same minor line.
sbt> updateScalaVersionsEach version is updated within its minor line:
2.13.12→ latest2.13.x2.12.18→ latest2.12.x3.3.1→ latest3.3.x
Updates Scala versions in the sbt-build group (build-level settings).
sbt> updateBuildScalaVersions| alejandrohdezma |