I did not find an easy way to debug gradle build script inside the IDE but the most convenient I found is to export GRADLE_OPTS before running the gradle build inside a terminal. Then use remote debug to connect the IDE to the JVM

Inside you terminal do

export GRADLE_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"

Then run your build

gradle clean install

Finally put some breakpoints and launch the remote debug configuration inside your IDE on the port 5005 and you’re good to go!