Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
sbt:plugins.sbt中的scalaVersion值_Scala_Sbt - Fatal编程技术网

sbt:plugins.sbt中的scalaVersion值

sbt:plugins.sbt中的scalaVersion值,scala,sbt,Scala,Sbt,有没有办法在plugins.sbt中获得scalaversation设置的值 我尝试在plugins.sbt内执行以下操作: logLevel := Level.Warn resolvers += "Typesafe repository" at "https://repo.typesafe.com/typesafe/releases/" addSbtPlugin("com.typesafe.play" % "sbt-plu

有没有办法在plugins.sbt中获得scalaversation设置的值

我尝试在plugins.sbt内执行以下操作:

logLevel := Level.Warn

resolvers += "Typesafe repository" at "https://repo.typesafe.com/typesafe/releases/"
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.7")

val version = scalaVersion.value
这就是我得到的错误:

错误:值只能在任务或设置宏中使用,例如:=, +=、++=、Def.task或Def.setting

我想在plugins.sbt中实现的是检索scalaVersion设置的值,并将该值与addSbtPlugin一起使用,如下所示:

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.7").filter(_ => version == "2.12")

此错误表示您无法读取任务或设置执行范围以外的设置值,因此您不应仅声明字段,而应在另一个任务或设置内使用,例如:

lazy val customVersion = settingKey[String]("Custom version for sake of example")

customVersion := {
  //`.value` referenced inside `customVersion` settings declaration, so sbt can evaluate customVersion in scope of other settings/task evaluations.
  "Custom version" + scalaVersion.value
}

你能把整个代码片段贴出来吗?此错误表示您的值声明位置错误。@Ivan Kurchenko,我更新了问题并发布了整个plugins.sbt文件,但我想这只与我声明val的那一行有关。正如您所看到的,我直接声明它,不在sbt任务中,也不在设置中,您可以尝试在
plugins.sbt
中详细说明您试图使用该版本实现的目标。这可能会为您提供信息:@Tomer Shetah,目标是将scala版本用于addSbtPlugin@TomerShetah,我已经更新了我的问题,我描述了我想要实现的目标,以及如何在plugins.sbt中检索新customVersion设置的值。我认为我属于第一种情况,因为我不能在任务/设置范围之外使用值。我的目标是检索scalaVersion,然后在plugins.sbt内与addSbtPlugin一起使用。@Helix112不是sbt只为特定的Scala版本添加插件吗?是的,我在解析插件时不试图强加scalaVersion,而是根据scalaVersion有条件地加载插件,我更新了问题,我正试图应用Golly的答案