Debug a Spring Boot application started in custom task in Intellij

Viewed 66

I use Spring Boot and want to execute Spotless to reformat code before bootRun everytime, so I write the following tasks in my build.gradle.kts:

task("startServer") {
    setGroup("Sample category")
    dependsOn(":security:spotlessApply", ":database:spotlessApply").finalizedBy(":convo:bootRun")
}

When I execute this task in debug mode, Intellij doesn't stop at the breakpoint, but if I execute the built-in bootRun task, it works.

How can I let Intellij debug the Spring Boot application started in my startServer tasks?

1 Answers

I find a way to achieve this, instead of writing a custom task, I add dependsOn directly in bootRun task in the application's (here is my convo module) build.gradle.kts:

tasks.withType<org.springframework.boot.gradle.tasks.run.BootRun>() {
    dependsOn(":database:spotlessApply").dependsOn(":security:spotlessApply")
}
Related