Debugging of a JVM application (Java or Scala) with breakpoints in Gradle and IntelliJ 2016.3.5

陌路散爱 提交于 2019-12-06 10:41:15

Debugging of gradle tasks like 'test', 'run', actually all gradle tasks that implements JavaForkOptions interface, should work in IntelliJ since 2014 year

Meanwhile, I found the solution myself. If you have a similar issue, follow the approach mentioned above using the debug option.

test {
    debug true
}

But make sure that external connections are accepted in the settings after IntelliJ restarted:

Then, it connects to the correct JVM and interrupts at the breakpoints using the remote task:

If you restart IntelliJ, however, with the very same option (external connections) enabled, then the debugging task might fail due to a blocked port:

So, for some reason, IntelliJ blocks that port after a restart but it is necessary to enable the setting for the debugging task to work. That's odd and I don't think it is intended to behave like that.

Anyways, if you disable the setting and restart, the port will be open again. Then, re-enable the setting, do not restart, just run the Gradle task, and the debugging task. It will work.

I hope this helps anyone else looking for an intermediate solution to debug JVM applications with Gradle and IntelliJ among the confusing and partially outdated answers out there. If anyone has a better or simpler suggestion, feel free to append your answer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!