2

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 Answer 1

6

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
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.