这就是我最终要做的。我没有使用应用程序插件的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
关闭它们。