lazy val buildDb = taskKey[Unit]("Initializes the database")
buildDb := {
(compile in Compile).value
val s: TaskStreams = streams.value
s.log.info("Building database")
try {
...
} catch {
case e: Throwable =>
sys.error("Failed to initialize the database: " + e.getMessage)
}
s.log.info("Finished building database")
}
這將產生以下錯誤SBT 0.13 taskKey宏不能與[Unit]一起使用?
C:\work\server\build.sbt:98: error: type mismatch;
found : Unit
required: T
s.log.info("Finished building database")
^
[error] Type error in expression
但如果我把它定義這樣lazy val buildDb = taskKey[String]("Initializes the database")
,然後添加到最後一行的任務"Happy end!"
串一切似乎工作。我該責怪,還是宏觀上有什麼問題?
如果最後一行是(),會發生什麼。我之前使用過taskKey [Unit],所以這裏有些東西看起來很不錯。 – jsuereth
它適用於SBT'0.13.2-M2'。你可以刪除try-catch塊並重新啓動它嗎?你可以在這個問題上加上'sbt'嗎? –
try/catch塊也引起了我的注意。我想知道你是否可能需要將其移至自己的方法。 –