How to debug remote spring boot appliaction in IntelliJ Ultimate with gradle project tool - spring-boot

I am new to IntelliJ and gradle and I want to debug my Spring boot application remotely , request is coming from UI and I need to debug the request ,
But not getting success , tried many thing followed JetBrain site and also tried to configure the debug setup.
but I m really getting frustrated, I guess I am not starting server in debug mode or doing something wrong.
Could anyone tell me how to set up the configuration in IntelliJ with Gradle Spring project?
getting error like:
Unable to open debugger port (localhost:8082): java.io.IOException "handshake failed - connection prematurally closed"
Edit: do I need to do anything else , my app is running on 8082 port no.
I am running my app normally as I do via cmd line ./gradlew bootRun

Unless you made some modifications to the Gradle build configuration (which I doubt being the case since you mentioned being new to Gradle), you should be able to start you application with a debugger attached to it using the --debug-jvm flag:
$ ./gradlew run --debug-jvm
and since you are using Spring Boot, you should rather use the bootRun task:
$ ./gradlew bootRun --debug-jvm
Once above command fired, your application will start and you should see below line in output:
Listening for transport dt_socket at address: 5005
stating that the JVM debugger is waiting for a client to attach on port 5005 which should be the same as your IntelliJ IDEA | Remote JVM Debug configuration port. Change the port from 8082 to 5005 for your Store_Debug configuration then click on the 🐛 icon and you should see a message stating that your debugger is attached:
Connected to the target VM, address: 'localhost:5005', transport: 'socket'

Related

"./gradlew bootRun --debug-jvm" is not working as it should be

I am trying to debug the Spring Boot application with cmd "./gradlew bootRun --debug-jvm", earlier it was working fine but now when I am trying to build with cmd and trying to debug the code, my application is not going up. It is building without any error but still, application is not going up.
getting Listening for transport dt_socket at address: 5005 this message too.
IDK what happened , and i changed nothing in build.gradle, what can be the reason?
Debug can be turned on in different ways. Check the value of GRADLE_OPTS environment variable and org.gradle.jvmargs Java system property.
Latter can be set in different places: on the project level (in gradle.properties in project root) or in global config ~/.gradle/gradle.properties.
Setting suspend to n will allow you to both run the process in debug mode and do not wait for the debugger.
More info can be found here

How can I debug gradle plugin

I have written an andrioid gradle plugin with IntelliJ.And I used it in an Android application.I would like to debug the plugin.So I tried to create a remote debug in IntelliJ
Then do something in Android Studio.
Excute
export GRADLE_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
and
./gradlew showTips --no-daemon
.The result is the IJ debugger can connect to VM,but did not STOP at the breakpoint.
My plugin code is this
The resule in IJ is this ,and never stop at the breakpoint
Connected to the target VM, address: 'localhost:5005', transport: 'socket'
Disconnected from the target VM, address: 'localhost:5005', transport: 'socket'
What can I do to make the breakpoint to be useful
I think you also need to set a debug property for gradle. -Dorg.gradle.debug=true
org.gradle.debug
When set to true, Gradle will run the build with remote debugging enabled,
listening on port 5005. Note that this is the equivalent of adding
-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005
to the JVM command line and will suspend the virtual machine until a
debugger is attached.
https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties

Unable to debug tomcat server using eclipse

I'm using:
Spring Tool Suite Version: 3.2.0.RELEASE
Tomcat v7.0.42
When I just run my tomcat server everything is fine but I'm unable to debug it even locally. It produces following error:
Startich Apache Tomcat v7.0.42 at localhost has encoutered a problem.
Server Apache Tomcat v7.0.42 bat localhost was unable to start within 45 seconds. If the server requires more time, try increasing the timeout in the server editor.
I've tried the following:
increase the timeout.
remove all the apps before starting the debugging.
install new instance of tomcat (the only configuration that I've did on fresh install is turning on Use Tomcat installation and Never publish automatically).
But it didn't help, I still can only run the tomcat, without the debug option. Does anyone know how to make this debugging work?
When I've used new, clear workspace for Spring Tool Suite, debugging started to work.
Cheers,

Debug gradle jettyRun in IntelliJ

I run Jetty from the command line with:
export GRADLE_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=9999,server=y,suspend=n"
gradle jettyRun
and see:
Listening for transport dt_socket at address: 9999
... then in IntelliJ Idea (Ultimate 12.1.3) I create a new remote debug configuration with all defaults, changing only the port to 9999.
When I start (debug) using the remote configuration, I see:
Connected to the target VM, address: 'localhost:9999', transport: 'socket'
... which makes me think everything is working as expected.
Then I make requests that should result in hitting breakpoints. But the breakpoints are never triggered.
What am I doing wrong?
Thanks.
You could have the "org.gradle.jvmargs" variable set in your gradle.properties file. This causes the JVM to be forked which means you are no longer debugging the right process.
In this case, you could either not set the "org.gradle.jvmargs" or pass it the debug parameters eg.
org.gradle.jvmargs=-XX:MaxPermSize=128m -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=1233
Setting the debug parameters in org.gradle.jvmargs would configure the forked process for debugging.
In IntelliJ (at least on 12.1.5) you can just go to JetGradle, right click on jettyRun and then click on Debug.

tomcat debugging

I am working on a project where the backend code is in Java.
I want to debug this code and am running tomcat in the debug mode correctly .
I have the Java code in Eclipse where I set up a new debug config for Remote Java Application and start the debugging.It shows no error but it is not breaking at the breakpoint.
So the Tomcat Webapps folder has only a copy of the Servlet classes and my Java code is in a folder at some other place.
Is this the reason that I am not being able to link them properly
You have to start tomcat with the JPDA options in order to debug remotely. Under *nix, issue "catalina jpda start" instead of "catalina start".
If you want to do a remote debug to figure out a problem in code, then your code locally must be the same. Also remember to connect to the correct port, 8000, I believe.

Resources