Processing 4.x + IntelliJ - How to properly debug a custom library

I’m looking for a better debugging experience to make my library more robust. This is about developing libraries for processing using IntelliJ (*). It is not about debugging a sketch running in Processing.

I would like to set breakpoints in the code and have the execution halts at such breakpoints.
Here is what I tried:

  • Start PDE, open a sketch that uses the custom library, run the sketch.
  • From IntelliJ, Run > Attach to Process. Select the process for the running sketch.

Result: Error.

Error running 'localhost:8070': Unable to open debugger port (127.0.0.1:8070): java.net.ConnectException "Connection refused (Connection refused)"

(*) I assume the question would apply to Eclipse but I can’t say for sure.

emphasized text