4

看起来当我尝试在不同的窗口中为同一个项目运行第二个 Gradle 任务时,第二个任务被锁住了。有没有直接的方法解决这个问题?

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

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

我正在使用 Gradle 2.7。

4

1 回答 1

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

关闭它们。

于 2015-10-22T03:00:53.480 回答