How to execute runMain from custom task?
If anybody wanted to run the main class with arguments computed basing on settings, you need dynamic tasks. For example:
val myRun = taskKey[Unit]("...")
myRun := Def.taskDyn {
val appName = name.value
Def.task {
(runMain in createApi in Compile)
.toTask(s" com.softwaremill.MyMain $appName")
.value
}
}.value
TaskKey[Unit]("myTask") := (runMain in Compile).toTask(" com.example.Main arg1 arg2").value
runMain
is an InputTask
. InputTask
has toTask
method since 0.13.1.
- https://github.com/sbt/sbt/commit/9dcb8727d819fb
- https://github.com/sbt/sbt/blob/v0.13.6/main/settings/src/main/scala/sbt/InputTask.scala#L33
- http://www.scala-sbt.org/0.13/docs/Input-Tasks.html#Get+a+Task+from+an+InputTask