I can debug remotely by configuring the run task. Since this is a JavaExec task, it supports the jvmArgs properties:
run { jvmArgs "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005" }
and debugging properties:
run { debug true }
Right-clicking for debugging does not work, because IntelliJ is attaching the debugger to the wrong JVM ie gradle.
source share