Run all microservices in a multi-project gradle build

柔情痞子 提交于 2021-02-11 08:24:09

问题


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?


回答1:


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)



来源:https://stackoverflow.com/questions/35684313/run-all-microservices-in-a-multi-project-gradle-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!