SBT make one project compile with only one version of scala

Viewed 64

In sbt with a multiproject setup, is there a way to make sure that one of the projects compiles with only version of Scala. Eg

/foo (scala-2.13.8)
/bar (scala-2.12.15, scala-2.13.8, scala-3.1.1)
/baz (scala-2.12.15, scala-2.13.8, scala-3.1.1)

So basically I want bar and baz to cross compile where as foo to compile only for scala-2.13.8

Is this possible? What would the build config look like?

1 Answers

It is possible if you don't have dependencies from baz or bar to foo.

For example, the following build.sbt will only compile foo with version 2.13.8 when you call sbt +compile

ThisBuild / scalaVersion := "2.13.8"
ThisBuild / crossScalaVersions := Seq("2.12.15", "2.13.8", "3.1.1")

val foo = project.settings(
  crossScalaVersions := Seq("2.13.8")
)
val bar = project
val baz = project
Related