2

我有以下设置键:

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,顺便说一句)

4

1 回答 1

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
于 2013-09-12T14:56:04.653 回答