I've been struggling to debug a Grails 2.5.0 app from inside IntelliJ. Specifically, I'm finding it difficult to configure the app such that
- functional tests can be debugged
- functional tests can be run
- the app can be debugged
- the app can be run
when (1) and (2) are launched from inside IntelliJ (version 14.1.4).
Here's a toy Grails app I'm using to investigate this issue, which has a single functional test. The key to getting debugging working seems to be these JVM forking settings BuildConfig.groovy.
grails.project.fork = [
// configure settings for compilation JVM, note that if you alter the Groovy version forked compilation is required
// compile: [maxMemory: 256, minMemory: 64, debug: false, maxPerm: 256, daemon:true],
// configure settings for the test-app JVM, uses the daemon by default
test : [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, daemon: true, jvmArgs: jvmArgs],
// configure settings for the run-app JVM
run : [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve: false, jvmArgs: jvmArgs],
// configure settings for the run-war JVM
war : [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve: false],
// configure settings for the Console UI JVM
console: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256]
]
// Include the line below to debug functional tests from IntelliJ. The tests should be launched in Debug mode from IntelliJ
//grails.project.fork = null
Debug run-app (3)
With forking enabled, the app can be debugged by running it from inside IntelliJ, then launching a remote debugger from the IDE to connect to the app on port 5005. The JVM forking settings ensures that the app always runs with remote debugging enabled, so be sure to launch the app by running it, rather than debugging it.
Debug functional tests (1)
To debug functional tests, you need to include this line
grails.project.fork = null
such that forking (and remote debugging is disabled. Then you can debug the functional tests by launching the test via an IntelliJ debug configuration.
It's fairly tedious to have to include/comment out this line depending on whether it's the app or a functional test that's being debugged, so I'm looking for a simpler solution.
One might think this could be avoided with
if (Environment.current == Environment.TEST) {
grails.project.fork = null
}
But for some unknown reason, this does not work.