How to run additional task at the end of gradle bootRun

1.3k Views Asked by At

I have server application that I run using gradle bootRun.

I also have script runUpdate.sh that I need to run from command line of terminal after application is started.

I created gradle task that run this script:

task runUpdate(type: Exec) {
    commandLine './runUpdate.sh'
}

Now I want to run this script from bootRun automatically. With no need to execute additional step manually. How can I do it?

2

There are 2 best solutions below

0
On

I'm using this the command shouldRunAfter to define that my task run before the bootRun

task runUpdate(type: Exec) {
    commandLine './runUpdate.sh'
}

// This will set te bootRun to wait your task run first
bootRun.configure {
    shouldRunAfter runUpdate
}
2
On

https://docs.gradle.org/current/userguide/more_about_tasks.html

you can use gradle dependsOn here is a sample code

bootRun{
  dependsOn runUpdate
}
task runUpdate(type: Exec) {
    commandLine './runUpdate.sh'
}