Showing console with Spring Boot, Gradle and IDEA - spring-boot

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..

Related

Debugger, #SpringBootTest, and Gradle

I'm new to Spring Boot and Gradle and cannot figure out how to suspend JUnit tests and connect to them with a debugger.
I invoke the automated tests on the command line gradlew build. What I'd like is so the execution to pause wen it reaches the test task and wait for a debugger to connect.
The JUnit test classes are annotated like this:
#RunWith(SpringRunner.class)
#SpringBootTest
#ActiveProfiles("test")
#AutoConfigureMockMvc
I have tried adding the JVM arguments for debugging to the gradle.properties file and I still can't get it to suspend, much less listen on a port for the debugger. I'm not sure what information to provide you -- ask me in the comments for files, code, or settings.
Gradle 5.5
Spring Boot 2.16
Java 11
#Omid. Thank you for the link. The solution was simple.
UPDATE: Do not use gradlew build. Use the test task instead.
gradlew test --debug-jvm
In the Gradle 5.5.1 docs:
https://docs.gradle.org/current/userguide/java_testing.html#sec:debugging_java_tests

How do I get a gradle property into intellij while debugging?

I write test automation. I'm using Log4j2 in my gradle project, and I do development with Intellij. My automation runs at the end of a build. And everything that happens when the automation runs is logged using Log4j2. I pass in the properties that Log4j2 needs via the build.gradle file. The config properties that I pass to Log4j2 are the location of the config file, where to put the output log file, and what logging level I want. But when I'm writing tests and running them manually in intellij, it's like I'm short-circuiting the build.gradle file, and I get no properties and no logging when I do. How do I fix that?

Spring Boot bootRun with continuous build

It should be possible to have a Spring Boot app continuously build (i.e. hot reload) by running gradle build --continuous and gradle bootRun in sequence.
I'm trying to modify the bootRun task in the gradle build file so that it calls the build task in continuous mode, but I can't seem to add arguments to it.
bootRun.dependsOn build
How can I get that build to run continuously?
This question and the corresponding answers are pretty interesting.
Short answer : you can't have the bootRun task running with the continuous option (if your app stays alive indefinitely)
But there is a hack by Stefan Crain :
To get it to live reload you need to have 2 terminals open.
gradle build --continuous
build --continuous will keep satisfying the initial build request until stopped
gradle build --continuous --quiet & 2>1 >/dev/null runs in the background, but you would miss the important build warnings/errors.
gradle --stop to stop watching.
gradle bootRun
bootrun starts with spring-boot-devtools on classpath, which will detect changes and restart application.
I think it's what you are looking for.
Another option to Toyonos solution seems to work for me, run the commands in two separate terminals to maintain the build warning messages:
gradle bootRun
gradle build --continuous

Running Gradle Wrapper commands resets Spring application.properties file

I have added spring.redis.host and spring.redis.port properties to the applications.properties file of my Spring boot application (Apache Fineract) in order to configure it with Redis. However, every time I run any gradle wrapper command, such as ./gradlew clean tomcatRunWar or ./gradlew build, the application.properties file gets reset to the initial version and my edits cannot be seen.
Is there any way for ensuring that gradle wrapper takes into consideration the custom edits that I am making to it? Thanks.

Does gradle continuous build support SpringBoot?

When I try to run build with gradle with the -t flag:
./gradlew clean build -x test -t
I get prompt line:
Waiting for changes to input files of tasks... (ctrl-d to exit)
but when I try it with bootRun command it doesn't work/appear:
./gradlew clean bootRun -t
Does it work with Spring Boot? (I know about Spring dev tools plugin - 1.3 is not released yet)
andy-wilkinson is correct in his answer : gradle bootRun never completes because some applications run indefinitely. Its well documented in this issue in the grails project.
I've found a way to force bootRun to live reload the application from the command line. The key items here are the gradle daemon and the spring-boot-devtools package.
To get it to live reload you need to have 2 terminals open.
gradle build --continuous
build --continuous will keep satisfying the initial build request until stopped
gradle build --continuous --quiet & 2>1 >/dev/null runs in the background, but you would miss the important build warnings/errors. gradle --stop to stop watching.
gradle bootRun
Bootrun starts with spring-boot-devtools on classpath, which will detect changes and restart application.
It depends on the nature of your Spring Boot application. If you app typically runs and then exits then continuous build will work. However if your app typically stays alive indefinitely, for example because it's a web app that handles HTTP requests, then it won't work. In the latter case the bootRun task never completes so Gradle doesn't know that it's time to start watching for changes.

Resources