As noted in the comments, I would be surprised if it is possible to debug a Gradle build script in VS Code since it wasn't that long ago that you couldn't even do that in IntelliJ1.
You may be able to get debugging to work by moving your Gradle logic into separate Java files; VS Code breakpoints may well work in Java files.
Extracting build logic into buildSrc folder
To move your logic to a Java file you can use the buildSrc folder. As an example of this:
Put a new Gradle build file at buildSrc/build.gradle ready to write Java code:
plugins {
id 'java'
}
Place your Java function in a Java class, say in buildSrc/main/java/MyBuildHelper.java:
import org.gradle.api.Project;
public class MyBuildHelper {
void helpMe(Project project) {
project.getTasks()
.create("myNewTask", task -> {
task.doLast(taskInner -> {
String output = taskInner.getName() + " is a runner!";
System.out.println(output);
});
});
}
}
This class is then exposed to your build script so you can write in your root build.gradle:
new MyBuildHelper().helpMe(project)
Now you can test it by running the new task added by the Java code:
$ ./gradlew myNewTask
which should print myNewTask is a runner! to the console.
This Java file may well be debuggable in VS Code using the methods you describe in your question. (Other JVM languages can be used in a similar fashion but I imagine Java support is more robust in VS Code.)
Use of Kotlin
You also asked about Kotlin. I would definitely recommend using Kotlin for your build file (and indeed as much of your code as possible! I am a Kotlin fan). This is because it is statically typed and will help you write correct code as you go along.
However I imagine Kotlin support on VS Code is not great. If you want to stick with VS Code, Kotlin may not be preferable if the VS Code support is insufficient; I cannot comment knowledgeably on Kotlin in VS Code. If you want to use Kotlin I would again push you to use IntelliJ (a step that I took a number of years ago and have not regretted).
1If you're not aware, IntelliJ IDEA is an application published by JetBrains, the authors of Kotlin, which is tightly integrated with Gradle, so they have a commercial interest in making IntelliJ IDEA work well with Gradle and Kotlin.
buildSrcfolder. This folder is compiled and made available to project build scripts