Since the ScriptEngine.eval()
method only takes the script as a String
or as a generic Reader
, I don't think it is possible to achieve this. The GroovyScriptEngineImpl
class will generate a script name and compile it to a class at runtime, which will make it hard (impossible?) for the debugger to know which breakpoint(s) are associated with the running script.
It might not be a solution for you, but if you instead invoke the script using GroovyShell
, then it pretty much works out of the box.
Example:
File file = new File(scriptDir, "ScriptToRun.groovy");
Binding binding = new Binding();
Object result = new GroovyShell(binding).evaluate(file);
Just remember to set the correct package in the script if it is not located at the root.