In the Create Run/Debug Configuration dialog, specify the necessary information and click OK.

Debugging Gradle tasks in Gradle Tool Window

Tasks available for debugging via Gradle tool window are the ones that implement org.gradle.process.JavaForkOptions
interface.
For example, test or
run. For debugging Gradle script tasks themselves, use a
Groovy run/debug configuration that appears in the context menu when you right-click on the script task in the editor.