:=
给一个Key设置为一个新值
name := "Hello"
+=
给一个Seq
类型的key追加一个值:
libraryDependencies += "org.apache.commons" % "commons-lang3" % "3.3.2"
++=
给一个Seq
类型的key追加多个值:
libraryDependencies += Seq(
"org.apache.commons" % "commons-lang3" % "3.3.2",
"org.scalaz" %% "scalaz-core" % "7.1.0"
)
~=
在key已有的值的基础上,修改为一个新值:
name ~= { n => n + "!!!" }
<<=
在一个key中使用另一个key的值
假设已经定义了一个key:
name := "Hello"
现在想在另一个key中直接使用它的值:
anotherKey <<= name
如果想在另一个值的基础上生成一个新值,可以:
anotherKey <<= name { n => n + "!!!"}
anotherKey2 <<= (name, anotherKey) { (n,a) => n + a }
可用来判断一个key是否有值
lazy val unintiedKey = settingKey[String]("Unitialized key")
lazy val someKey = settingKey[String]("Key to check the value of another")
someKey := unintiedKey.?.value getOrElse "new value"
这时someKey
的值是:
new value
但是如果已经给unintiedKey
赋了值,比如:
unintiedKey := "Another value"
那么someKey
的值将会是:
Another value
跟?
有一点相似:
lazy val unintiedKey = settingKey[String]("Unitialized key")
lazy val someKey = settingKey[String]("Key to check the value of another")
someKey := (unintiedKey ?? "uninitedKey had no value").value
则someKey
的值是:
uninitedKey had no value
从文档上看到还有这一些奇怪的操作符,不知道有什么用。
<++=
<+=
不过万能的stackoverflow告诉我,自从sbt 0.13有了.value
以后,就再也不需要它们了。
http://stackoverflow.com/questions/25819886/where-are-examples-of-in-build-sbt