Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle: custom task with jvm arguments for Spring Boot

Trying to create a small custom gradle task for Spring Boot that originally looks like this:

gradle bootRun --debug-jvm

The task should look like this: gradle debugRun

I tried this but it does not work:

task debugRun(dependsOn: 'bootRun') << {
    applicationDefaultJvmArgs = ['--debug-jvm']
}

How can I pass this debug-flag to the bootRun task?

like image 969
Lugaru Avatar asked Dec 14 '25 15:12

Lugaru


1 Answers

It isn't sufficient for your debug run task to depend on the bootRun task. It needs to modify the existing bootRun task to enable debugging. You can do that by checking for the debugRun task in Gradle's task graph. If it's there, you set the bootRun task's debug property to true:

task debugRun(dependsOn:bootRun) {
    gradle.taskGraph.whenReady { graph ->
        if (graph.hasTask(debugRun)) {
            bootRun {
                debug = true
            }
        }
    }
}
like image 140
Andy Wilkinson Avatar answered Dec 16 '25 13:12

Andy Wilkinson