gpt4 book ai didi

scala - 为什么 sbt 一直告诉我添加 -deprecation 到 scalacOptions ?

转载 作者:行者123 更新时间:2023-12-01 09:36:28 25 4
gpt4 key购买 nike

下面是我的多项目结构:

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)

最佳答案

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

我使用的是 sbt 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"

有了这个,重新加载,谜团就揭开了。

➜  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 .

关于scala - 为什么 sbt 一直告诉我添加 -deprecation 到 scalacOptions ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24223839/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com