How to debug my Grails application in IntelliJ? - gradle

I am using this specific command to run my Grails application clean bootRun -Dgrails.env=test.
I would like run my application (with the same configuration) in debug mode from IntelliJ.
What Run/Debug configurations should be used to run the app in debug mode with the same options as in the command above?

Related

IntelliJ Gradle project, no test runner tab

I try the spock test framework with IntelliJ (2021.3.2), created the demo from https://blog.jetbrains.com/idea/2021/01/tutorial-spock-part-1-getting-started/ with the first simple test.
I don't see the test runner tab (even if I could run the tests). The Gradle configuration is set by default to run tests by using Gradle. If I switch the Gradle configuration to run tests using IntelliJ IDEA, I got the test runner tab.
How could I get the test runner tab with Gradle too?

How to debug apache camel route in quarkus application using eclipse

I want to know, is there anyway to debug my camel route using quarkus framework in eclipse
Start your Quarkus application in debug mode with JVM with;
./mvnw compile quarkus:dev -Ddebug
then attach a debugger to localhost:5005.
if u are use quarkus cli start your application with dev mode
quarkus dev
if u are not use quarkus cli u can use mvn for run quarkus app dev mode
mvn compile quarkus:dev
after run application add remote debugger from eclipse with default quarkus opens 5005 port for debugging

How to debug spring boot maven project in debug mode in Intellij?

I run my maven project with the following command for dev profile from my terminal
sudo mvn spring-boot:run -Dspring.profiles.active=dev
How can I run my project to run in debug mode with given profile. How to set configuration in intellij for this?
Running a Spring Boot project from Maven with a specific profile
mvn spring-boot:run -Dspring-boot.run.profiles=foo,bar
Or by using a shell variable
SPRING_PROFILES_ACTIVE=foo mvn spring-boot:run
Or by passing arguments to the JVM
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Dspring.profiles.active=foo,bar"
These are the only methods that I know of that work for Spring Boot v2.0+.
The first option is recognized by the Spring Boot Maven plugin and passes it on to the application JVM.
Since version 2.0 of Spring Boot, the run goal forks the process by default. Since -Dspring.profiles.active is not recognized by the plugin directly, it's only seen by the Maven process and not passed on to the app itself. This is why it doesn't work in the form mvn spring-boot:run -Dspring.profiles.active=foo,bar.
In the second option, the shell variable should be visible to any subprocesses spawned from that shell.
Starting a Spring Boot project in debug mode from Maven
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
Putting it together
mvn spring-boot:run -Dspring-boot.run.profiles=foo,bar -Dspring-boot.run.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
Alternative, passing all arguments to JVM
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005 -Dspring.profiles.active=foo,bar"
The Maven pom.xml should include the Spring Boot plugin
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.1.RELEASE</version>
</plugin>
In IntelliJ you should create a new "Remote" debug configuration from the "Run/Debug Configurations" tool window. You'll find it in the main menu - "Run / Edit Configurations..."
The default config will use the same 5005 port.
After that, launch that debug config. The console should display "Connected to the target VM...".
Sources:
https://docs.spring.io/spring-boot/docs/2.0.1.RELEASE/maven-plugin/examples/run-profiles.html
https://docs.spring.io/spring-boot/docs/2.0.1.RELEASE/maven-plugin/examples/run-debug.html
If you're running from maven, then add the following parameters:
mvn spring-boot:run -Dspring.profiles.active=dev -Drun.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5555"
Here 5555 is a debug port number (you can use any other unoccupied port).
Then in IntelliJ you can use Remote Debug configuration and connect to that port.
If you open the pom.xml from intelliJ, you can create a Run Configuration with --spring.profiles.active=dev and main class that is a class with method main just like in a regular the most simple java application.
Just click run button (green triable button) then click Debug...
IntelliJ will run your spring-boot app in debugging mode
If you want to run with arguments just open edit configuration and put your args in VM Options/Program arguments like

Showing console with Spring Boot, Gradle and IDEA

Working through setting up a spring boot project with gradle and Idea. I created a Run configuration calling the bootRun gradle task. It appears to run fine (I can hit the end point) but I dont see the same console output (I don't see any) that I see when I run ./gradlew bootRun from a terminal.
What am I doing wrong?
You need to toggle (/ab) below debug button(left side of console). See this picture..

How to debug deployed Grails application

Is there any way to debug Grails application deployed to production server in Intellij IDEA or any other IDE?
You need to start your server in debug mode by adding something like this to the java process start script:
-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
Then in IntelliJ open Run > Edit Configurations and select Defaults > Remote, where you can set the port you specified above to debug the remote JVM.
You can do the same in Eclipse.
Also you can use grails-debug run-app to debug Grails application. But I think it's not good choice for production
Also, starting from grails 2.3.0 the jvm is forked into the build vm and the application vm. Using --debug allow you to debug the build vm, and using --debug-fork allows you to debug the app vm. Grails 2.3 forked execution

Resources