Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 160 Vote(s) - 3.69 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to debug spring application with gradle

#1
I am working on spring app and need to step through a controller method to see how it works.
I am working in eclipse and building my app with `gradle bootRun` command.

How to run it in debug mode?

i tried `gradle bootRun --debug` but it's just debug log, not debug mode

i tried `gradle help --task bootRun` -- this gives me info about task
there i saw `--debug-jvm` option but when i run
`gradle bootRun --debug-jvm` application doesn't start
Reply

#2
After you run ```gradle bootRun --debug-jvm``` the application is suspended until you connect your debugger to the port it is listening on (port 5005).
Reply

#3
Define an executes a Java application in a child process.

task executeApp() {
doFirst {
println "Executing java app from Gradle..."
javaexec {
main = "com.mymain"
jvmArgs = ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=30000"]
}
}
}


Set your breakpoints in the java code. After execute the Gradle task.For example in Windows:

.\gradlew.bat executeApp

The task waits until you attach the debugger. For example in Netbeans go to Debug->Attach debugger , set 30000 on port Field.
Reply

#4
As a response to dankdirkd's answer above: ([compare][1])

gradle bootRun --debug-jvm

will make the gradle build run in debug mode. That probably is not what you want. What you want to achieve is that the springBoot task starts your application in debug mode.

The spring boot task extends the gradle [JavaExec][2] task. You can configure the bootRun task in your build.gradle file to add a debug configuration like this:

bootRun {
jvmArgs=["-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=32323"]
}

For the build.gradle.kts this would look like this (with suspend mode disabled):

tasks {
val bootRun by getting(BootRun::class) {
jvmArgs=listOf("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=32323")
}
}

If your server is within a cloud and you want to debug from local machine, you need to make sure that it allows connections from outside. Use below configuration in that case

tasks {
val bootRun by getting(BootRun::class) {
jvmArgs=listOf("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:32323")
}
}

Note that the address is now `0.0.0.0:port` instead of just `port`

[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#5
For `build.gradle.kts` file you can also simply use below:

tasks.withType<BootRun> {
jvmArgs = listOf("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:32323")
}
Reply

#6
I personally prefer going under `Gradle tasks` and `right-clicking on the bootRun`. This is useful in the IDE compared to the terminal.
Reply

#7
For people hitting this via Google and wondering how to enable Spring's debug mode (normally done by `java -jar app.jar --debug`) and using Gradle, [here is how][1]. This passes `--debug` to the main class which is how you turn on Spring Boot's debug mode which logs autoconfig classes among other things.

./gradlew bootRun --args='--debug'

[1]:

[To see links please register here]

Reply

#8
For those looking for IntelliJ example with gradle bootRun task:
1. Add following bootRun task definition to build.gradle file
```
bootRun {
jvmArgs "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"
}
```
2. Run bootRun task
3. Once you get to the point where console/terminal says
"Listening for transport dt_socket at address: 5005"
go to "Run --> Attach to Process..." and choose your app
4. Add breakpoints anywhere you want








Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through