score:4

Accepted answer

I created an SBT plugin for this.

project/plugins.sbt

resolvers += Resolver.sonatypeRepo("releases")

addSbtPlugin("com.lucidchart" % "sbt-cross" % "1.0")

build.sbt

lazy val foo = (project in file("foo")).dependsOn(baz_2_10).settings(
  scalaVersion := "2.10.4"
)

lazy val bar = (project in file("bar")).dependsOn(baz_2_11).settings(
  scalaVersion := "2.11.5"
)

lazy val baz = (project in file("baz")).cross

lazy val baz_2_10 = baz("2.10.4")

lazy val baz_2_11 = baz("2.11.5")

It takes a couple more lines, but now everything compiles as expected: sbt foo/compile works, and sbt bar/compile works.

You don't have to remember unique commands, you don't have bugs from crossPath := false, and unlike ++, this is parallelizable: sbt compile will compile foo, bar, and baz with the correct Scala versions concurrently.

score:0

I had a similar setup, and got it work like so:

lazy val baz = (project in file("baz")).settings(
  crossScalaVersions := Seq("2.10.4", "2.11.4")
)
lazy val bar = (project in file("bar")).dependsOn(baz).settings(
  scalaVersion := "2.10.4"
)
lazy val foo = (project in file("foo")).dependsOn(baz).settings(
  scalaVersion := "2.11.4"
)

And building with

sbt '++ 2.10.4 baz/compile' 'bar/compile' '++ 2.11.4 baz/compile' 'foo/compile'

score:10

Yevgeniy Mordovkin's proposed solution, to declare crossPaths := false in the baz project, works.

Another thing you might do, is to prepend a + before the command: sbt '+ bar/update'. That will build baz for all declared Scala versions.


Related Query

More Query from same tag