Skip to content
Latchkey

sbt "different Scala versions in the build" in CI

Two subprojects that depend on each other declare different scalaVersion values, so their compiled classes are binary-incompatible. sbt flags the mismatch during resolution or fails when one project puts the other on its classpath.

What this error means

sbt reports that modules were resolved with conflicting Scala versions, or a downstream project fails to compile against a dependency built for a different Scala binary version.

sbt
[warn] Multiple dependencies with the same organization/name but different versions:
[warn]  - org.scala-lang:scala-library:2.12.18
[warn]  - org.scala-lang:scala-library:2.13.12

Common causes

A subproject overrides scalaVersion locally

One module sets its own scalaVersion that differs from the rest of the aggregate, so its output cannot link against sibling projects.

A dependency drags in a second scala-library

A library built for a different Scala binary version brings its own scala-library, putting two versions on the classpath.

How to fix it

Set one Scala version in ThisBuild

  1. Declare scalaVersion once in ThisBuild so every subproject inherits it.
  2. Remove per-project scalaVersion overrides unless cross-building intentionally.
  3. Run sbt evicted to confirm a single scala-library remains.
build.sbt
ThisBuild / scalaVersion := "2.13.12"

Cross-build deliberately with crossScalaVersions

If you truly need multiple Scala versions, cross-build with crossScalaVersions and + so each is published separately rather than mixed.

build.sbt
crossScalaVersions := Seq("2.12.18", "2.13.12")
// sbt +compile builds for each

How to prevent it

  • Define scalaVersion once in ThisBuild.
  • Cross-build explicitly instead of setting different versions per project.
  • Use sbt evicted in CI to detect duplicate scala-library versions.

Frequently asked questions

What causes ""different Scala versions""?
One module sets its own scalaVersion that differs from the rest of the aggregate, so its output cannot link against sibling projects.
How do I fix "different Scala versions"?
Set one Scala version in ThisBuild

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card