如何让 SBT 密钥查看当前配置的设置? [英] How can i make an SBT key see settings for the current configuration?

查看:22
本文介绍了如何让 SBT 密钥查看当前配置的设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 build.sbt 文件:

version := "0.0.1"

version in Test := "0.0.1-DEBUG"

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

虽然版本在测试"配置中似乎是正确的,

and while the version seems to be right in the "test" configuration,

> show test:version
[info] 0.0.1-DEBUG

这个名字似乎没有看更具体的设置.

the name doesn't seem to look at the more-specific setting.

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

这显然是我真正想做的事情的一个大大简化的例子,但我认为它说明了问题/误解.

This is obviously a greatly-simplified example of what i'm really trying to do, but i think it illustrates the problem/misunderstanding.

EDIT (2013-07-04):我真正想做的是更改 IntegrationTest 配置中的 javaOptions (b/c 我们启动一个服务,然后针对它运行测试代码,我希望被测试的服务在稍微沙盒的模式下运行).在 IntegrationTest 中设置 javaOptions 很容易(并且 show it:java-options 确认),但实际上并没有被 runner 使用,除非我麻烦明确定义 it:runner 以使用 it:java-options.我本来希望 *:runner 更喜欢最具体的依赖变量.

EDIT (2013-07-04): What i'm really trying to do is change javaOptions in the IntegrationTest configuration (b/c we spin up a service and then run testing code against it, and i'd like the service being tested to run in a slightly sandboxed mode). Setting javaOptions in IntegrationTest is easy enough (and show it:java-options confirms), but doesn't actually get used by runner unless i go to the trouble of explicitly defining it:runner to use it:java-options. I would have expected *:runner to prefer the most-specific dependent vars.

推荐答案

这是你的 Build.scala 按照@MarkHarrah 的建议翻译为使用 inConfig:

Here's your Build.scala translated to use inConfig as suggested by @MarkHarrah:

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)
  )
}

这篇关于如何让 SBT 密钥查看当前配置的设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆