3

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?

marko
  • 2,841
  • 31
  • 37
Lugaru
  • 1,430
  • 3
  • 25
  • 38

1 Answers1

7

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
            }
        }
    }
}
Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242