For me tibtof's answer was only half what I needed ot make it work. After I explicitly added the package name, jdb would yield "Try compiling with debugging on" on this gradle project of mine:
> Unable to set deferred breakpoint package.ClassName:LineNumber : No linenumber information for package.ClassName. Try compiling with debugging on.
In this case, if you are using gradle you need to make sure that options.debug=true in the compileJava task, which you can check with the println below.
In my case I was compiling with debugging on - or so I thought. I had my build.gradle like so (based on this answer and this article):
tasks.withType(JavaCompile) { options.compilerArgs << '-Xlint:all' << '-Werror' << '-g' options.debug = project.hasProperty('debug') options.debugOptions.debugLevel = 'source,lines,vars' options.debugOptions.debugLevel = 'source,lines,vars' doLast { println "Args for for $name are $options.allCompilerArgs" println "debug=$options.debug" } }
When I ran ./gradlew build -Pdebug it printed as expected:
Args for for compileJava are [-Xlint:all, -Werror, -g] debug=true
It turns out that when I later run ./gradlew runMyTask --debug-jvm it re-ran the compileJava task because I did not pass -Pdebug again. Running gradle with --info confirms it:
Task ':compileJava' is not up-to-date because: Value of input property 'options.debug' has changed for task ':compileJava'
This fact only became apparent after a few hours when I added the aforementioned println:
afarah@gentoopc $ ./gradlew runMyTask --debug-jvm > Task :compileJava Args for for compileJava are [-Xlint:all, -Werror, -g] debug=false > Task :runMyTask Listening for transport dt_socket at address: 5005
So the solution was to run ./gradlew runMyTask --debug-jvm -Pdebug, i.e. pass -Pdebug again:
afarah@gentoopc $ ./gradlew runMyTask --debug-jvm -Pdebug > Task :compileJava Args for for compileJava are [-Xlint:all, -Werror, -g] debug=true > Task :runMyTask Listening for transport dt_socket at address: 5005
Notice debug=true now, and finally jdb did not complain and stopped at my LineNumber breakpoint.