问题
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.
回答1:
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
来源:https://stackoverflow.com/questions/23615745/pick-up-different-source-file-for-different-scala-version