7

I have a multi-project sbt build (each project is micro service). For development convenience, I want to run all of them at the same time. Is it possible with sbt?

lazy val root = (project in file("."))
  .aggregate(
    serviceA,
    serviceB
  )

lazy val serviceA = (project in file("service-a"))
 ...

 lazy val serviceB = (project in file("service-b"))
 ...

I can run them individually with serviceA/run or serviceB/run

But I need to run serviceA and serviceB with single sbt command (they will be running on different ports)

baitmbarek
  • 2,440
  • 4
  • 18
  • 26
Teimuraz
  • 8,795
  • 5
  • 35
  • 62
  • Try the `bgRun` task to run in background. to run two tasks at the same time use `all A B` command. – laughedelic Dec 04 '19 at 23:58
  • Unfortunately it doesn't work with play framework https://github.com/playframework/playframework/issues/9505 – Teimuraz Dec 05 '19 at 00:05
  • we use Ammonite to call multiple sbt commands: http://ammonite.io/#SBTIntegration – pme Dec 05 '19 at 08:14
  • @pme could you please provide some example or give more info? – Teimuraz Dec 05 '19 at 10:54
  • @laughedelic where is `all` declared? – steinybot Nov 27 '20 at 06:38
  • @steinybot you can see its name in the code is [`MultiTaskCommand`](https://github.com/sbt/sbt/blob/e1d8f0cafd56bc299e561fbd7823b5a443f07802/main/src/main/scala/sbt/internal/CommandStrings.scala#L23), then it's mentioned [here](https://github.com/sbt/sbt/blob/e1c7704e6c012cf047fc209fc0ca55908270d9de/main/src/main/scala/sbt/internal/Act.scala#L455), but the further digging for its definition I'll leave to you :) – laughedelic Nov 27 '20 at 11:16

1 Answers1

1

You could try to use Ammonite

We us Ammonite scripts (e.g. runner.sc) to run sbt. I never used Future as we run one thing after the other.

Or use a simple bash file:

Your requirement is more or less running sbt in the background. Here is an according question: how-to-run-sbt-as-daemon

Taking this to your question, this could look like:

#!/usr/bin/env bash

sbt -Djline.terminal=jline.UnsupportedTerminal serviceA/run &
sbt -Djline.terminal=jline.UnsupportedTerminal serviceB/run &

I couldn't test this, let me know if it works.

pme
  • 14,156
  • 3
  • 52
  • 95
  • 1
    Kinda not working.. I see that both services started, but when I hit endpoints of first via postman it never ends... second service is completely down.. – Teimuraz Dec 05 '19 at 21:17