我尝试了所有我能想到的但是运行taskB仍然会出现错误消息,如果我将其置于自定义配置中,则*/*:taskB
或*/cmd:taskB
中的任务未定义。
Command.command("doStuff", Help.more("doStuff", "whatever")) {
(state: State) =>
val e = Project.extract(state)
val taskA = taskKey[Seq[String]]("A")
val taskB = taskKey[Seq[File]]("B")
val cmdConfig = config("cmd")
val newState = e.append(
inConfig(cmdConfig)(Seq(
taskA := {
// do stuff
},
taskB := {
// do stuff
}
)
)
, state
)
val result: (State, Seq[File]) = e.runTask(taskB in cmdConfig, newState)
)
调试时,structure.data
中搜索的任务似乎不存在。
答案 0 :(得分:2)
首先,我假设您只想从命令中调用任务,而您并不关心是否通过修改该命令中的状态来添加它们。
如果是这样,我会采用更标准的方式,因为它是由AutoPlugins完成的。
import sbt._
import Keys._
object MyPlugin extends AutoPlugin {
object autoImport {
val taskA = taskKey[Seq[String]]("Task A")
val taskB = taskKey[Seq[File]]("Task B")
}
import autoImport._
val cmdConfig = config("cmd")
override def projectConfigurations = Seq(cmdConfig)
// this is optional of course, you can also enable plugin manually
override def trigger = allRequirements
override def projectSettings =
Seq(commands += doStuffCommand) ++
inConfig(cmdConfig)(Seq(
taskA := {
println("TASK A")
Seq("A", "B")
},
taskB := {
println("TASK B")
Seq(file("."))
}
))
lazy val doStuffCommand =
Command.command("doStuff", Help.more("doStuff", "whatever")) {
(state: State) =>
val e = Project.extract(state)
val (newState, bResult) = e.runTask(taskB in cmdConfig, state)
newState
}
}
除此之外,你根本不需要一个命令,只是让一些任务调用另一个任务会更简单。