简体   繁体   English

如何根据提供的scala版本告诉sbt需要编译哪个包

[英]how to tell sbt that which package needs to be compiled based on provided scala version

I am using sbt cross build my project supports two scala versions scala-2.12.8 and scala-2.13.1 and accrodingly i have source code directoroes as我正在使用 sbt cross build 我的项目支持两个 scala 版本scala-2.12.8scala-2.13.1并且scala-2.12.8我有源代码scala-2.12.8

src/main/scala_2.12
src/main/test_2.12

src/main/scala_2.13
src/main/test_2.13

i looked at the sbt documentation its not clear from it then i found this answer here is my code我查看了 sbt文档,从中不清楚,然后我发现这个答案是我的代码

unmanagedSourceDirectories in Compile <+= (scalaVersion, sourceDirectory in Compile) {
  case (v, dir) if v startsWith "2.12" => dir / "scala_2.12"
  case (v, dir) if v startsWith "2.13" => dir / "scala"
}

and am getting the following error并收到以下错误

info] Loading project definition from /home/git/testproj/project
/home/git/testproj/build.sbt:54: error: (sbt.SettingKey[String], sbt.SettingKey[java.io.File]) does not take parameters
unmanagedSourceDirectories in Compile <+= (scalaVersion, sourceDirectory in Compile) {
                                                                                     ^
[error] Type error in expression
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? 

It's build-in in sbt since 0.13.something for cross compilation:从 0.13.something 开始,它就内置在 sbt 中,用于交叉编译:

src/main/scala      - shared compiled sources
src/main/scala-2.11 - version-specific compiled sources
src/main/scala-2.12
src/main/scala-2.13

src/test/scala      - shared test sources
src/test/scala-2.11 - version-specific test sources
src/test/scala-2.12
src/test/scala-2.13

And for any configuration you created (eg it , functional-test , or whatever you name it) it will be:对于您创建的任何配置(例如itfunctional-test或您命名的任何配置),它将是:

src/$config/scala               - common code
src/$config/scala-$scalaVersion - version specific code

This was described in documentation in Scala-version specific source directory section.这在Scala 版本特定源目录部分的文档中有所描述。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM