I want to override the default behaviour of the run task in order to preprocess the arguments passed to the sbt command and call the run task on a specific subproject with different arguments (depending on custom logic). That's a sample of build.sbt file:
lazy val core = (project in file("core"))
lazy val bar = (project in file("bar"))
lazy val foo = (project in file("foo"))
run := Runner.buildRunTask(bar, foo).value.evaluated
The buildRunTask override the task with the new implementation. Here the code:
def buildRunTask(runnableProjects:Project*) : Initialize[InputTask[Unit]] =
Def.inputTask {
val args: Seq[String] = spaceDelimited("<arg>").parsed
val availableProjects = runnableProjects.map(_.id).mkString(",")
if (args.length == 0) throw new IllegalStateException(s"you need to specify a valid command. Available commands are: '$availableProjects'")
val command = args head
val project = runnableProjects.find(_.id == command)
.getOrElse(throw new IllegalStateException(s"invalid command '$command'. Available command are: $availableProjects"))
val newArgs = transformArgs(args.rest)
//TODO: how I can compile and execute the run task only for the project passed as argument? I want something like project.runTask(newArgs) ?
}
Do you have any suggestion?
Thanks!
Regards
Gianluca