在同一项目中同时运行两个Gradle应用程序任务

时间:2015-10-21 17:37:37

标签: gradle gradle-plugin

看起来当我尝试在不同的窗口中为同一个项目运行第二个Gradle任务时,第二个会阻塞锁定。有一个直截了当的方法吗?

我尝试做的事情:我的项目有几个服务器子项目都使用应用程序插件。我想同时开始(例如$ gradle :server1:run),以便我可以连接并试用它们。

我知道我可以编写一个任务来将两个服务器部署到测试区域并在那里启动它们,但是应用程序:运行任务在开发一个应用程序时很方便,所以我想将它用于两个如果可能的话。

我正在使用Gradle 2.7。

1 个答案:

答案 0 :(得分:1)

这是我最终做的事情。我使用run而不是使用应用程序插件的installDist任务,并编写了一个简单的任务来运行生成的启动脚本。然后我通过创建一个存储在src/dist/bin下的简单服务脚本来扩展它。该脚本处理启动,停止和状态操作。最终结果:

ext.installDir = "$buildDir/install/" + project.name
ext.command = "$installDir/bin/" + project.name

task start(type:Exec, dependsOn:'installDist') {
  description "Starts the " + applicationName + " application"
  workingDir "$installDir"
  commandLine "$command", "start"
}

task stop(type:Exec, dependsOn:'installDist') {
  description "Stops the " + applicationName + " application"
  workingDir "$installDir"
  commandLine "$command", "stop"
}

task status(type:Exec, dependsOn:'installDist') {
  description "Displays the " + applicationName + " application status"
  workingDir "$installDir"
  commandLine "$command", "status"
}

现在,从父项目我可以输入:

$ gradlew start

启动两台服务器和

$ gradlew stop

将它们关闭。

相关问题