I have the following gradle task that works fine:
abstract class StartDevTask : DefaultTask() {
private val developmentTasks = listOf(
"dev-db",
"run",
"watch"
)
@TaskAction
fun startDevelopmentTasks() {
developmentTasks
.map { ProcessBuilder("./gradlew", it).start() }
.map {
Thread { it.waitFor() }.also { it.start() }
}
.map { it.join() }
println("All processes finished")
}
}
// registering the task over here
tasks.register<StartDevTask>("start-dev")
Then I can Invoke from the command line:
$ ./gradlew start-dev
Which works just fine, but when I kill the process with Ctrl+C and check how many processes are alive with:
$ ps -ax | grep gradlew
I can see a lot of those leftover processes, to remove them I can just run ./gradlew --stop
My question is; how can I run ./gradlew --stop
after that task is killed? Or can someone hint me to a better alternative of doings this?
Thanks!!