Sbt 如何添加第一次运行编译的任务

Sbt 如何添加第一次运行编译的任务,sbt,Sbt,我想首先运行一个依赖于编译任务的任务(例如,类似于run,但与另一个主类一起运行) 我看到的示例似乎使用了任务的值,这取决于。然而,我不知道编译的价值是什么,我也不明白为什么我关心它 我假设所需的值是(编译中编译)。值我该如何处理它 例如,在build.sb中有一个hello任务 lazy val hello = taskKey[Unit]("Prints 'Hello World'") hello := println("hello world!") 我想我还有最后一句话要说 hello

我想首先运行一个依赖于编译任务的任务(例如,类似于run,但与另一个主类一起运行)

我看到的示例似乎使用了任务的值,这取决于。然而,我不知道编译的价值是什么,我也不明白为什么我关心它

我假设所需的值是
(编译中编译)。值
我该如何处理它

例如,在build.sb中有一个hello任务

lazy val hello = taskKey[Unit]("Prints 'Hello World'")

hello := println("hello world!")
我想我还有最后一句话要说

hello := {
  val dummy = (compile in Compile).value
  println("hello world!")
}
这是正确的吗?

如果是这样的话,编译的价值是什么?我应该用它做些什么呢?这绝对是定义依赖关系的最好方法


可能仅仅出于学术原因,另一种选择可能是:

mainClass in Compile := Some("org.example.Main1")

val mainClass2 = taskKey[Option[String]]("Defines the alternative main class.")
val run2 = inputKey[Unit]("Runs the alternative main class, passing along arguments provided on the command line.")
run2 <<= Defaults.runTask(fullClasspath in Runtime, mainClass2 in Compile, runner in run)

mainClass2 in Compile := Some("org.example.Main2")
> run
[info] Running org.example.Main1
main1
[success] Total time: 0 s, completed 20-Apr-2015 22:59:49
> run2
[info] Running org.example.Main2
main2
[success] Total time: 0 s, completed 20-Apr-2015 22:59:48