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.
[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.12Common 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
- Declare
scalaVersiononce inThisBuildso every subproject inherits it. - Remove per-project
scalaVersionoverrides unless cross-building intentionally. - Run
sbt evictedto confirm a singlescala-libraryremains.
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.
crossScalaVersions := Seq("2.12.18", "2.13.12")
// sbt +compile builds for eachHow to prevent it
- Define
scalaVersiononce inThisBuild. - Cross-build explicitly instead of setting different versions per project.
- Use
sbt evictedin CI to detect duplicatescala-libraryversions.