4

I am using SBT 0.13.2 (could be e.g. 0.13.5 just as well) and am trying to take a project written for 2.10 and cross-compile it for both 2.9 and 2.10. It uses scala.util.hashing.MurmurHash3, which doesn't exist in 2.9; instead there's scala.util.MurmurHash (which may not be compatible???). My source will need to be different to handle the imports in different places and the different interfaces. I presume I need to have two different .scala files and somehow tell SBT to compile one .scala file when compiling for 2.9, and a different .scala file for 2.10. How do I do this?

Thanks.

Urban Vagabond
  • 7,282
  • 3
  • 28
  • 31

1 Answers1

1

You can append to unmanagedSourceDirectories:

lazy val commonSettings = Seq(
  scalaVersion := "2.10.4",
  unmanagedSourceDirectories in Compile +=
    (sourceDirectory in Compile).value / ("scala_" + (scalaBinaryVersion.value match {
      case v if v startsWith "2.9." => "2.9"
      case v => v
    }))
)

lazy val root = (project in file(".")).
  aggregate(app).
  settings(commonSettings: _*)

lazy val app = (project in file("app")).
  settings(commonSettings: _*)

Now, src/main/scala_2.10 is part of the source directory for Scala 2.10.x, and src/main/scala_2.9 for Scala 2.9.x.

Update:

There's now a pull request opened by @indrajitr Enable cross-version support for Scala sources. #1799

Eugene Yokota
  • 94,654
  • 45
  • 215
  • 319