如何在编译Build.scala时设置SBT使用的scalacOptions?

时间:2014-06-18 15:41:43

标签: scala sbt

在编译scalacOptions时,我在尝试弄清楚如何设置/附加到SBT使用的Build.scala时遇到了一些麻烦。我团队中的某个人从Akka的Build.scala复制了一些代码,结果是一堆不赞成的警告和一个功能警告。

$ reload
[info] Loading global plugins from /Users/xxx/.sbt/0.13/plugins
[info] Loading project definition from /Users/xxx/yyy/zzz/project
[info] Compiling 1 Scala source to /Users/xxx/yyy/zzz/project/target/scala-2.10/sbt-0.13/classes...
[warn] there were 3 deprecation warning(s); re-run with -deprecation for details
[warn] there were 1 feature warning(s); re-run with -feature for details
[warn] two warnings found

我尝试过的事情

  1. scalacOptions ++= Seq("-unchecked", "-feature")添加到build.sbt。我希望在编译Build.scala之前加载它。
  2. scalacOptions ++= Seq(...., "-unchecked", "-feature")
  3. 中已有Build.scala
  4. 尝试在scalacOptions之前设置reload,但似乎已被丢弃

    $ ;set scalacOptions ++= Seq("-feature", "-deprecated") ;reload
    [info] Defining zzz/*:scalacOptions
    [info] The new value will be used by zzz/compile:scalacOptions
    [info] Reapplying settings...
    [info] Set current project to zzz (in build file:/Users/xxx/yyy/zzz/)
    [info] Loading global plugins from /Users/xxx/.sbt/0.13/plugins
    [info] Loading project definition from /Users/xxx/yyy/zzz/project
    [info] Compiling 1 Scala source to /Users/xxx/yyy/zzz/project/target/scala-2.10/sbt-0.13/classes...
    [warn] there were 3 deprecation warning(s); re-run with -deprecation for details
    [warn] there were 1 feature warning(s); re-run with -feature for details
    [warn] two warnings found
    [warn] Discarding 1 session setting.  Use 'session save' to persist session settings.
    
  5. 通过大量的血汗,我能够找到弃用警告的原因,但我无法找到功能警告的原因。

1 个答案:

答案 0 :(得分:7)

Sbt is recursive,表示Build.scala目录中的project由其父目录中的另一个定义或build.sbt目录中的project构建。

因此,您必须在build.sbt目录中创建project。在project/build.sbt中,您应该可以设置scalacOptions ++= Seq("-unchecked", "-feature")