Content
To configure a Grails 3 application for remote debugging, you need to make adjustments to the application's startup scripts. Here's a step-by-step guide:
1. Edit BuildConfig.groovy:
Open the `BuildConfig.groovy` file in the root of your Grails 3 project, and add the following lines inside the `dependencies` block:
groovy:
dependencies {
// other dependencies...
compile 'org.grails.plugins:grails-debug:3.0.0'
}
This will add the Grails Debug Plugin to your project.
2. Configure the debug port:
Open the `grails-app/conf/application.yml` file and add the following configuration for the debug port. If the `application.yml` file doesn't exist, create one.
grails:
debug:
enabled: true
port: 5005
This sets the debug port to 5005. You can choose a different port if needed.
3. Run your application in debug mode:
Open a terminal and navigate to your project's root directory. Run the following command:
./gradlew bootRun --debug-jvm
If you are on Windows, use `gradlew.bat` instead of `./gradlew`:
gradlew.bat bootRun --debug-jvm
4. Publish Remote Debuger's Port in deploy script
Make changes to deploy.sh file by adding --publish 5005:5005 argument to the docker run command:
docker run --publish 8088:8080 --publish 5005:5005 --detach --name dev-omnipaycoinatm omnipaycoinatm-dev
5. Connect your debugger:
In your favorite IDE (such as IntelliJ IDEA or Eclipse), create a remote debugging configuration:
- IntelliJ IDEA:
- Go to Run > Edit Configurations, click on the "+" icon, and choose "Remote" from the list.
- Set the host to `localhost` or the remote host your application is running on
- Set the port to `5005` (or the port you specified in the configuration).
- That will generate the following in the "Command line arguments for remote JVM" field:
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
- Eclipse:
- Go to Run > Debug Configurations, right-click on "Remote Java Application," and choose "New."
- Set the host to `localhost` and the port to `5005` (or the port you specified in the configuration).
Now, you can start the remote debugger from your IDE. It will connect to your Grails application, allowing you to set breakpoints, inspect variables, and debug your code.
Remember to remove or disable the debug configuration in a production environment and only use it for development purposes.