nerdherd
nerdherd

Reputation: 2603

Run all microservices in a multi-project gradle build

I have a multi-project gradle build that's roughly set up like this:

RootProject
- ServiceA
- ServiceB
- ServiceC
- UI

Each of these subprojects is using the Spark framework and runs an embedded web server. It's basically a microservices setup, so they all need to be up and running for the system as a whole to work.

They each have a task defined like this:

task runApp(type: JavaExec) {
    main = 'App'
    classpath = sourceSets.main.runtimeClasspath
}

I know I can manually start each service either through my IDE or by opening a different terminal for each sub-project and running gradlew ServiceA:runApp, but what I'd like to do is create a runSystem task at the root level that will fire up everything to make it easy to run the whole system during development.

How can I do this with Gradle?

Upvotes: 2

Views: 1480

Answers (1)

RaGe
RaGe

Reputation: 23647

If you run a task on the root project, Gradle invokes the same task (if it exists) on all the subprojects. Just execute runApp from the root folder.

In your case however, your runApp task might not exit because it starts a server, so execution will not move on to the next project. You can either enable parallel execution, or modify your tasks to run your server tasks in the background (using ProcessBuilder)

Upvotes: 2

Related Questions