-1

我正在使用 sbt 交叉构建我的项目支持两个 scala 版本scala-2.12.8scala-2.13.1并且我有源代码目录作为

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

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

我查看了 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"
}

并收到以下错误

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? 
4

1 回答 1

0

它自 0.13 以来就内置在 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

对于您创建的任何配置(例如it,functional-test或任何您命名的配置),它将是:

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

这在Scala-version specific source directory部分的文档中进行了描述。

于 2020-04-02T08:58:31.187 回答