How can I debug gradle plugin - debugging

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

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 to debug remote spring boot appliaction in IntelliJ Ultimate with gradle project tool

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'

Breakpoints not hit when trying to do remote debug in IntelliJ

I am running the following command on command prompt
mvnDebug cuke4duke:cucumber
and then trying to attach from IntelliJ to remote debug code.
I get the following messages in InteliJ but breakpoint's never get hit
Connected to the target VM, address: 'localhost:8000', transport: 'socket'
Disconnected from the target VM, address: 'localhost:8000', transport: 'socket'
Note - My code is not stale, it is upto date.

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.

Running remote JBoss in debug mode, Bootup Time Issue

I am trying to run remote jboss in debug mode to debug my application and i have set
set JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y %JAVA_OPTS%
in run.bat file, and am trying to start the jboss server using ant jboss.start but it is taking some time and then timing out, am not sure why this is happening, is there a way out?
Also as jboss is timing out, I would like to increase bootup time for the server, how can i do it from the command line?
Side note, server.log file does not show any messages which jboss is trying to bootup in debug mode (not sure if this would help but thought so sharing this info.)
Any clue or suggestions?
You should set:
suspend=n
in debugger startup settings.
suspend - True if the target VM is to be suspended immediately before the main class is loaded; false otherwise.
Your JBoss waits infinitely for debugger connection, this is useful when you want to troubleshoot startup issues, otherwise do not suspend your VM and let the debugger be connected any time you want.
I was frustated to get jboss started in debug mode through command line
Finally following seemed to work
1.Below should be the last line in /bin/run.conf.bat
rem # Sample JPDA settings for remote socket debugging
set JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n %JAVA_OPTS%
If there is anything below this, delete it.
2.Also when you are running jboss from command prompt please check whether -Xdebug is at the start of JAVA_OPTS.
Then it should display following message
Listening for transport dt_socket at address: 8787
3.In eclipse use 127.0.0.1 instaed of localhost.
I don't know the reason behind it...but when I changed localhost to 127.0.0.1 it worked
(Make sure you replace localhost with 127.0.0.1 at 2 locations 1.Eclipse remote debug and 2.URL while running your application in browser)
Also check project name.
Sometimes we need to change the port number.
I never had such issues with tomcat.

Resources