Debugging Kotlin script in a Java app

I have a Kotlin script running inside a Java app via JSR 223 API. I’d like to be able to debug it in IDEA debugger. For example, I set the script’s folder as one of the source folders in the project, I set a breakpoint in the script, I compile and run the app from the IDE, load and execute the Kotlin script from the app and I’d like the breakpoint to be triggered. When I try it like this, the breakpoint does not work.

The same approach works perfectly for the Groovy script engine – scripts and breakpoints are recognized by the IDE and the execution stops on breakpoints inside the scripts.

Is it possible for the Kotlin script engine?

– Anton

1 Like

After a bit of exploration, it seems like the breakpoints do not work in the main script code that being executed by the compile(), eval() sequence. If I register some Kotlin callbacks with the main app Java code and the app calls those callbacks, Intellij debugger does stop at the breakpoint in the callbacks.

Interesting.
Sounds like IntelliJ’s debugger isn’t attaching to the right thing when there are only breakpoints in the script. But if it’s already attached, any breakpoints in a script run are hit.

I found breakpoints were working for me in my Kotlin script (not JSR 223) but I should be able to do the same test and see if it applies there as well–I suspect I always had multiple breakpoints when I was debugging.