如何在函数中获取类似baseDirectory的SettingKey的值?

时间:2013-09-12 07:05:02

标签: sbt

我有以下设置键:

val filterValues = SettingKey[Map[String, String]]("filter-values")

在定义设置时如此:

filterValues := Map(
    "someKey" -> sys.props.get("some.path").getOrElse(localPath("example"))
    …
)

...
private def localFile(path: String): String = ((baseDirectory) { _ / path })(_.getAbsolutePath)

但我得到的是以下类型不匹配:

Build.scala:8: type mismatch;
[error]  found   : sbt.Def.Initialize[String]
[error]  required: String
[error]   private def localFile(path: String): String = ((baseDirectory) { _ / path })(_.getAbsolutePath)

这样做的正确方法是什么? (对于sbt 0.13,btw)

1 个答案:

答案 0 :(得分:2)

您应该在设置初始化程序中提取设置的值,并将其传递给函数:

filterValues := Map(
    "someKey" -> sys.props.get("some.path").getOrElse(localPath(baseDirectory.value, "example"))
    …
)

...
private def localFile(base: File, path: String): String = (base / path).getAbsolutePath