SpringBoot 2 debug using the Gradle plugin - java

I am trying to remote debug a Spring Boot 2.0 web application, built and run with the new Spring Boot Gradle plugin. I've read that the way to go is to pass the --debug-jvm option like so:
./gradlew bootRun --debug-jvm
But I get the following:
Problem configuring task :bootRun from command line.
> Unknown command-line option '--debug-jvm'.
Has something changed in Spring Boot 2.0 or am I missing something? The new gradle plugin reference does not mention anything regarding debug.
I am running Spring Boot and spring-boot-gradle-plugin version 2.0.0.M6, gradle version 4.3.1.

The following would work:
Edit build.gradle
bootRun {
jvmArgs = ["-agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n"]
}
Execute./gradlew bootRun
Attach the debugger after the Spring Boot application has started (port 8000 in the specific case)

Related

Cannot locate tasks that match 'spring-boot:run' as project 'spring-boot' not found in root project 'demo'

I am new to Java and Spring and am trying to run the demo program from the Spring official quickstart tutorial
upon reaching the point where it tells me to enter gradlew.bat spring-boot:run into CMD, I get the error Cannot locate tasks that match 'spring-boot:run' as project 'spring-boot' not found in root project 'demo'.
I am using Java version 19.0.2 and Spring Boot version 3.0.2.
The guide is incorrect. The correct task is bootRun:
https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#running-your-application
./gradlew bootRun
The spring-boot:run the guide specifies is for the Maven Spring Boot plugin: https://docs.spring.io/spring-boot/docs/current/maven-plugin/reference/htmlsingle/#run

How to run java Google App Engine locally with app-gradle-plugin for yaml?

I am using Google App Engine gradle plugin with yaml file, but the plugin version for it has no task appengineRun or appengineStart like the appengine-web.xml version.
TL;DR appengineRun is only available for appengine-web.xml based projects. If you want to use app.yaml, you must provide your own server, for example Spring Boot with Jetty or Tomcat.
To run your application locally, you must provide your own server.
This guide shows how to test your application using app.yaml alongside with the app-gradle-plugin, on section Testing your application with the development server:
During the development phase, you can run and test your application at any time in the development server by invoking Gradle:
gradle jettyRun
Alternatively, you can run Gradle without installing it by using the Gradle wrapper.
As said on this comment on GitHub:
If you want to use app.yaml from your root directory, you must upgrade to Java 11. Learn more here. With the Java 11 runtime, you must provide your own server, for example Spring Boot with Jetty or Tomcat. The appengine:run goal does not work for app.yaml based projects because each server has a different start up command i.e. spring-boot:run for Spring Boot.

Spring Boot Tomcat won't start on specific port

I want to run a Spring Boot application using Maven but when I run
mvn clean install spring-boot:run -Dserver.port=8888
Spring runs on port 8080. How should I run a Maven Spring Boot application on a specific port?
I use Spring Boot version 2.2.6.
-Dserver.port is not passed to the JVM running your app.
You have to use
mvn clean install spring-boot:run -Dspring-boot.run.arguments="--server.port=8888"
Read more about this:
https://www.baeldung.com/spring-boot-command-line-arguments

Use IDEA Run/Debug Configuration to debug Gradle web app with Jetty plugin

What's the problem?
Is it possible to debug a Gradle web app running via Jetty plugin (using jettyRun or jettyRunWar) by using a IntelliJ IDEA Run/Debug Configuration?
I know that it is possible (I've done it before) to do it with Maven/Tomcat7 plugin and creating a simple Maven Run/Debug Configuration with the clean package tomcat7:run goals.
I've tried to create a Gradle Run/Debug Configuration with the clean jettyRunWar tasks. If I Run the configuration, everything works well. But the Debug option is not working as expected: the application actually runs, but debugger won't connect.
However, I did manage to debug the project by running on debug mode externally, like this:
$ export GRADLE_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=9999,server=y,suspend=n"
$ ./gradlew clean jettyRunWar
And then creating a Remote Run/Degug Configuration with all the default configurations except the port, which was set to 9999.
But that's not the solution I was looking for. I want to be able to debug the project by only clicking a button. Am I missing something?
Not in the mood to read everything? Here's an example
I've created a simple IDEA/Gradle/Jetty web app using Jersey available on Github here. The problem can be reproduced by:
Cloning the repository
Importing it on IDEA
Creating a Gradle Run/Debug Configuration for the root project with the clean jettyRunWar tasks
Debug using the configuration
The debugger won't connect and breakpoints won't work.
I am using:
IntelliJ IDEA Community Edition 2016.1.3 (OS X)
Gradle 2.7 (a wrapper is available on the Git repository, so it doesn't matter)

Executing without spring-boot:run failed

I can't run my spring boot app simply with java -jar because it doesn't listen to the port. But if I run the same app with Intellij idea and spring boot maven plugin with command spring-boot:run its ok. Why?

Categories