pick up different source file for different Scala version

廉价感情. 提交于 2021-02-04 20:01:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!