How do you attach a debugger to gradle so that I can debug it running a task?

So what are the correct steps in order to debug a gradle script ?