在多项目Gradle构建中运行所有微服务 [英] Run all microservices in a multi-project gradle build

查看:67
本文介绍了在多项目Gradle构建中运行所有微服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多项目gradle构建,其大致设置如下:

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

RootProject
- ServiceA
- ServiceB
- ServiceC
- UI

每个子项目都使用Spark框架并运行嵌入式Web服务器.这基本上是一个微服务设置,因此它们都需要启动并运行才能使整个系统正常工作.

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
}

我知道我可以通过IDE手动启动每个服务,也可以为每个子项目打开一个不同的终端并运行 gradlew ServiceA:runApp ,但是我要做的是创建根目录级别的 runSystem 任务将启动所有内容,以便在开发过程中轻松运行整个系统.

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.

如何使用Gradle做到这一点?

How can I do this with Gradle?

推荐答案

如果您在根项目上运行任务,则Gradle会在所有子项目上调用同一任务(如果存在).只需从根文件夹执行 runApp .

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.

但是,在您的情况下,您的runApp任务可能不会退出,因为它启动了服务器,因此执行不会继续进行到下一个项目.您可以启用并行执行,也可以修改任务以在后台运行服务器任务(使用 ProcessBuilder )

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)

这篇关于在多项目Gradle构建中运行所有微服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆