Question

Hi I would like to know if using SBT is possible to cross compiling against different Scala version using different sources for some classes. To keep back compatibility basically but leverage also on the new language features. Thanks.

Was it helpful?

Solution

You can add additional source directories based on scala version by adding to the unmanagedSourceDirectories setting.

Something like this:

unmanagedSourceDirectories in Compile <+= (scalaVersion, sourceDirectory in Compile) {
  case (v, dir) if v startsWith "2.9" => dir / "scala_2.9"
  case (v, dir) if v startsWith "2.10" => dir / "scala_2.10"
}

Should allow you to have three directories:

src/main/scala      # both 2.9 and 2.10
src/main/scala_2.9  # source only for 2.9
src/main/scala_2.10 # source only for 2.10
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top