如何设置SBT键查看当前配置的设置?

时间:2013-07-02 23:30:23

标签: scala sbt

我有以下build.sbt文件:

version := "0.0.1"

version in Test := "0.0.1-DEBUG"

name <<= (version) apply { v:String => "demo-%s".format(v) }

虽然版本似乎在“测试”配置中正确,

> show test:version
[info] 0.0.1-DEBUG

该名称似乎没有查看更具体的设置。

> show name
[info] demo-0.0.1
> show test:name
[info] demo-0.0.1

这显然是我正在努力做的一个非常简化的例子,但我认为这说明了问题/误解。

编辑(2013-07-04):我真正要做的是在javaOptions配置中更改IntegrationTest(我们正在启动服务,然后针对它运行测试代码,我希望测试的服务以略微沙盒模式运行)。设置javaOptions in IntegrationTest很容易(show it:java-options确认),但实际上并没有被runner使用,除非我明确定义it:runner使用{{ 1}}。我希望it:java-options更喜欢最具体的依赖变量。

2 个答案:

答案 0 :(得分:2)

我在sbt 0.11和0.12.1中尝试了这个并且它有效:

version := "0.0.1"

version in Test := "0.0.1-DEBUG"

name <<= (version) apply { v:String => "demo-%s".format(v) }

name in Test <<= (version in Test) apply { v:String => "demo-%s".format(v) }

<强>更新

如果您使用的是Build.scala文件,则可以跨项目推广此任务。这是一个例子:

import sbt._
import sbt.Keys._

object DemoBuild extends Build {

  lazy val demo = Project(
    id = "demo",
    base = file("."),
    settings = Project.defaultSettings ++ Seq(
      organization := "com.demo",
      scalaVersion := "2.10.0"
    ) ++ addNameAndVersion("0.0.1", "demo")
  )


  def addNameAndVersion(projectVersion:String, projectName:String):Seq[sbt.Project.Setting[_]] = {
    Seq(
      version := projectVersion,
      version in Test :=  projectVersion + "-DEBUG",
      name <<= version.apply(s => "%s-%s".format(projectName, s)),
      name in Test <<=  (version in Test).apply(s => "%s-%s".format(projectName, s))
    )
  }

}

答案 1 :(得分:2)

根据@MarkHarrah的建议,您的Build.scala已翻译为使用inConfig

import sbt._
import sbt.Keys._

object DemoBuild extends Build {

  val mySettings = Seq(
    name <<= version { v => "demo-%s".format(v) }
  )

  lazy val demo = Project(
    id = "demo",
    base = file("."),
    settings = Project.defaultSettings ++ Seq(
      organization := "com.demo",
      scalaVersion := "2.10.0",
      version := "0.0.1",
      version in Test <<= version { v => "%s-DEBUG".format(v) }
    ) ++ mySettings
      ++ inConfig(Test)(mySettings)
  )
}