Does gradle continuous build support SpringBoot? - spring

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.

Related

Trigger ./gradlew test when files have changed

I am building a Spring Boot REST API application and using Kotlin as the language.
For the development I am using IntellJ as the IDE.
The project structure looks as follows:
Is there a way to watch changes in the folder src to trigger the gradle task ./gradlew test after files have been changed?
You can use Gradle's support for continuous builds:
./gradlew test --continuous
This will cause Gradle to watch the filesystem for changes and execute the test task and any tasks upon which it depends whenever a change is detected.
You can right click the gradle task and set it to be done e.g. after each build.

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

Unable to run multiple gradle commands on same projects

I have a situation where i need to run multiple gradle tasks, in parallel.
For example: I am using gretty(org.akhikhl.gretty:gretty:+) plugin for running embedded webserivce, which runs my service.
So I ran, gradle jettyStart.
Now I have some scripts that need to be ran while the webservice is running, means the gradle jettyRun has run.
I have a migration script written in groovy, which I can call using gradle runScript <script_name>
but since this scripts calls the webservice apis, i need the service to be up. But the case is, once i keep running gradle jettyRun, i cant run gradle runScript until unless i stop the other tasks.
How can I resolve this issue.
You can use start (e.g. appStart) family of gretty tasks which starts jetty in background and exits. Then you can use any other gradle task on this project. To stop jetty you can use stop-tasks
You can get list of available tasks from documentation:
http://akhikhl.github.io/gretty-doc/Gretty-tasks.html

How to have Buildship recognize existing projects in Eclipse Mars

I just converted my Maven project to a gradle project. It was a multi project structure:
master-project
pom.xml
---->project1
-------->pom.xml
---->project2
-------->pom.xml
---->project3
-------->pom.xml
I ran a gradle init on it and have this structure now:
master-project
build.gradle
---->project1
-------->build.gradle
---->project2
-------->build.gradle
---->project3
-------->build.gradle
Everything builds fine, and I have been able to get some things done with that I couldn't figure out how to do with Maven, so that's great. Next step was to integrate that into the IDE since the Maven Dependencies are gone since I have removed the pom.xml files.
However the project isn't recognized as a gradle project - and I am not sure how to change that?
In Eclipse Mars it's still recognized as a Maven build, not gradle....
Thanks in advance.
EDIT: I reimported the projects which enabled the plugin for Eclipse. Now I am having weird behavior.
The build works from the command line, however when attempting the same execution from within Eclipse, it fails trying to copy the file dependencies.
For example:
Couldn't copy dependency jakarta-regexp-1.4.jar
java.nio.file.NoSuchFileException: C:\Users\user.m2\repository\jakarta-regexp\jakarta-regexp\1.4\jakarta-regexp-1.4.jar -> build\jfx\app\lib\jakarta-regexp-1.4.jar
I haven't changed the repo from maven yet - just changed the build scripts. This is running from the master project. So I am confused as to why the script would work from the commandline but not from within eclipse.
EDIT 2: Turns out this behavior is also present when running from the command line when the --daemon flag is set. Is there anyway to run the tasks without the daemon in Buildship? Or perhaps a way to fix this issue when the --daemon flag is enabled?
Thanks.
The issue with the build was that there is a leak in the JDK when bundling the JRE with the native app. This only happens when running with the --daemon flag (which all IDEs user). Therefore until this is fixed you will need to run gradle --stop and then run the clean.
The plug in I am using is no longer running the native task when running with --daemon.

Gradle wrapper and daemon

As many of you already know, the Gradle daemon can speed considerably Gradle.
I have a multimodule build and using Gradle wrapper.
When running from the command line:
gradlew :MyModule:test
Gradle spends some seconds analyzing my modules. If I launch again, it consumes the valuable time again and again.
I'm using Gradle 1.12.
I've tried to set add this line:
org.gradle.daemon=true
to local.properties, but no luck.
I don't know if I have to change myHome/.gradle/gradle.properties or some other file.
org.gradle.daemon=true has to be added to gradle.properties, not local.properties.

Resources