Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run multiple sbt projects in parallel?

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)

like image 889
Teimuraz Avatar asked Dec 04 '19 23:12

Teimuraz


People also ask

Can sbt execute tasks in parallel?

By default, sbt executes tasks in parallel (subject to the ordering constraints already described) in an effort to utilize all available processors. Also by default, each test class is mapped to its own task to enable executing tests in parallel.

What does sbt clean do?

clean Deletes all generated files (in the target directory). compile Compiles the main sources (in src/main/scala and src/main/java directories). test Compiles and runs all tests. console Starts the Scala interpreter with a classpath including the compiled sources and all dependencies.

What is Project in file in sbt?

A project is defined by declaring a lazy val of type Project. For example, : lazy val util = (project in file("util")) lazy val core = (project in file("core")) The name of the val is used as the subproject's ID, which is used to refer to the subproject at the sbt shell.


Video Answer


1 Answers

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.

like image 133
pme Avatar answered Nov 15 '22 06:11

pme