为什么sbt一直告诉我在scalacOptions已经添加-deprecation?

时间:2014-06-14 20:08:31

标签: scala sbt

以下是我的多项目结构:

myApp
  + build.sbt
  + sub-prj-1
      + build.sbt
  + sub-prj-2
      + build.sbt
  + project
      + Build.scala

我用来定义project/Build.scala中的常用设置,如下所示:

import sbt._
import Keys._

object ApplicationBuild extends Build {

  val defaultScalacOptions = Seq(
    "-unchecked", "-deprecation", "-feature", "-language:reflectiveCalls", "-language:implicitConversions",
    "-language:postfixOps", "-language:dynamics", "-language:higherKinds", "-language:existentials",
    "-language:experimental.macros", "-encoding", "UTF-8", "-Xmax-classfile-name", "140")

  val defaultResolvers = Seq(
    "Typesafe releases repository" at "http://repo.typesafe.com/typesafe/releases/"
  )

  val defaultSettings = Defaults.defaultSettings ++ Seq(
    scalaVersion := "2.10.4",
    scalacOptions ++= defaultScalacOptions,
    resolvers ++= defaultResolvers
  )
}

...然后我在每个build.sbt文件中引用这些常用设置:

name := "myapp"

organization := "Test, Inc."

version := "1.0"

ApplicationBuild.defaultSettings // it looks like common settings defined in
                                 // project/Build.scala are not read...

scalacOptions += "-feature"      // already defined in ApplicationBuild.defaultSettings...
                                 // but if I don't define it here, it doesn't work

lazy val `sub-prj-1` = project.in(file("sub-prj-1"))

lazy val `sub-prj-2` = project.in(file("sub-prj-2"))

lazy val brix = project.in(file(".")).settings(
  publishArtifact := false
).aggregate(
  `sub-prj-1`,
  `sub-prj-2`
)

例如,scalacOptions += "-feature"已定义Build.scala ...但如果我未在build.sbt中定义,我总会收到以下警告:

[warn] there were 1 deprecation warning(s); re-run with -deprecation for details
[warn] one warning found

有什么想法吗?我错过了什么吗?我在安装sbt 0.13.5之后首先出现了这个问题。

修改

以下是scalacOptions的内容:

[info] sub-prj-1/*:scalacOptions
[info]  List(-unchecked, -deprecation, -feature, -language:reflectiveCalls, -language:implicitConversions, -language:postfixOps, -language:dynamics, -language:higherKinds, -language:existentials, -language:experimental.macros, -encoding, UTF-8, -Xmax-classfile-name, 140)
[info] sub-prj-2/*:scalacOptions
[info]  List(-unchecked, -deprecation, -feature, -language:reflectiveCalls, -language:implicitConversions, -language:postfixOps, -language:dynamics, -language:higherKinds, -language:existentials, -language:experimental.macros, -encoding, UTF-8, -Xmax-classfile-name, 140)
[info] myapp/*:scalacOptions
[info]  List(-unchecked, -deprecation, -feature, -language:reflectiveCalls, -language:implicitConversions, -language:postfixOps, -language:dynamics, -language:higherKinds, -language:existentials, -language:experimental.macros, -encoding, UTF-8, -Xmax-classfile-name, 140)

1 个答案:

答案 0 :(得分:5)

我只能猜测(并指出错误时需要更正的其他信息),但warn消息来自构建项目(在project下)而不是你的。

我正在使用0.13.6-SNAPSHOT(根据今天的消息来源制作)所以你的里程可能会有所不同。

➜  myApp  xsbt
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Loading project definition from /Users/jacek/sandbox/common-settings/myApp/project
[info] Updating {file:/Users/jacek/sandbox/common-settings/myApp/project/}myapp-build...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Compiling 1 Scala source to /Users/jacek/sandbox/common-settings/myApp/project/target/scala-2.10/sbt-0.13/classes...
[warn] there were 1 deprecation warning(s); re-run with -deprecation for details
[warn] one warning found
[info] Set current project to brix (in build file:/Users/jacek/sandbox/common-settings/myApp/)

当我尝试重现您的情况时,我最终得到了project下的构建定义的消息:

[warn] there were 1 deprecation warning(s); re-run with -deprecation for details
[warn] one warning found

他们想要摆脱它们吗?如果是这样,请继续阅读。否则,请在您的问题中添加其他信息。感谢。

对于sbt is recursiveproject下面的内容是另一个构建定义(依此类推)。

为了消除这些消息,您应该遵循他们的建议并将-deprecation添加到相应项目的构建定义中。将以下内容添加到 project / build.sbt

scalacOptions += "-deprecation"

有了这个,reload和神秘就被揭开了。

➜  myApp  xsbt
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Loading project definition from /Users/jacek/sandbox/common-settings/myApp/project
[info] Compiling 1 Scala source to /Users/jacek/sandbox/common-settings/myApp/project/target/scala-2.10/sbt-0.13/classes...
[warn] /Users/jacek/sandbox/common-settings/myApp/project/Build.scala:15: value defaultSettings in object Defaults is deprecated: 0.13.2
[warn]   val defaultSettings = Defaults.defaultSettings ++ Seq(
[warn]                                  ^
[warn] one warning found
[info] Set current project to brix (in build file:/Users/jacek/sandbox/common-settings/myApp/)
>

As sbt.Defaults says

@deprecated("0.13.2", "Default settings split into `coreDefaultSettings` and IvyModule/JvmModule plugins.")

要解决此问题,请阅读文章Preview of upcoming sbt 1.0 features: Read about the new plugins