Reputation: 689
I am using sbt 0.13.5. I have several sub projects in my project, in particular a spray client and a spray route server. I want to be able to define several "run" commands, like runClient and runServer. for each sub project, I create a mainClass and set it up in the sbt file. Now, I would like to be able to: - launch several sbt in different terminal sessions. - in one session, type runClient - in the other session, type runServer. Is there a proper way to do that in sbt? I tried to define runServer as a new command:
def runServer = Command.command("runServer") { state =>
println("run Server")
run in Compile in server
state
}
def runClient = Command.command("runClient") { state =>
println("run Client")
run in Compile in client
state
}
where server is my server project. I add runServer in the commands of the project :
lazy val root = Project(id = "myproject", base = file("."),
settings = commands ++= Seq(runServer, runClient)
).aggregate(client, server)
In sbt, if I type runServer, the println works, but nothing is launched. Do you know how to execute the "run" statement?
Thanks.
Upvotes: 2
Views: 1763
Reputation: 13749
I don't think you have to resort to commands to achieve what are you looking for. Simple tasks should be enough.
There is a caveat though. The run
task, is an input task, and you have to convert it to normal task before referencing it.
val client, server = project
val runServer = taskKey[Unit]("Runs server")
val runClient = taskKey[Unit]("Runs client")
runClient := (run in Compile in client).toTask("args to the main class").value
runServer := (run in Compile in server).toTask("args to the main class").value
Now you should be able to run your server using runServer
and client using runClient
.
Note also that you can run both commands using server/run
and client/run
without resorting to custom tasks or commands.
Upvotes: 1