hfhc2
hfhc2

Reputation: 4391

How to debug grails applications

I am currently involved in the development of an application based on grails (version 3.12). Unfortunately I am not familiar with the ecosystem surrounding the framework. I would like to fix some bugs which are present in the code, but I am unclear about how to debug the application.

I read that remote debugging is the best bet for grails applications. This actually sort of works: I added a "Remote" execution profile in intellij and launched grails like this:

export GRAILS_OPTS="agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"
grails run-app

This does however have the effect that I have to launch the remote twice in intellij. I figured that this is due to the fact that grails has two forks of the JVM running (one for the compilation / etc and one forthe execution). Also, apparently a new JVM is forked whenever the source code changes.

My question is: How can I get the grails options through to the right JVM process via the configuration?

I found an older similar thread here. This does however apply to grails 2 and not grails 3. In particular, the buildConfig.groovy is gone and adding things like

grails.project.fork = [
    // ...
    run: [maxMemory:1024, minMemory:64, debug:false, maxPerm:256, jvmArgs: '..arbitrary JVM arguments..']
    // ...
]

to build.gradle causes exceptions to be thrown.

Upvotes: 1

Views: 872

Answers (1)

Jeff Scott Brown
Jeff Scott Brown

Reputation: 27220

There are several ways to do what you are asking about. One approach that doesn't involve needing to change the default generated build file or set any environment variables is the run the application like this:

./gradlew bootRun --debug-jvm

That will cause startup to pause until you connect the remote debugger. I do that a lot.

Another option is to open Application.groovy, right click and select "Debug...".

Upvotes: 1

Related Questions