Running Gradle Wrapper commands resets Spring application.properties file - spring

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.

Related

Spring boot version 2.5.5 unable to create docker image for copy command

After upgrading my spring-boot application from spring-boot version 2.3.9 to 2.5.12
We have started getting below exception. Not sure if there is change related to docker in spring boot version 2.5.12
With previous version it was working fine but after changing gradle to 6.8 and spring-boot version this issue started ... any workaround to fix this issue?
This is the command that causes error in Dockerfile
ENV APP_HOME=/app/z-api/
COPY --from=build "${APP_HOME}build/libs/z-api-*.jar" app.jar
COPY --from=build "${APP_HOME}build/libs/z-api-*.jar" app.jar
When using COPY with more than one source file, the destination must be a directory and end with a /
There are now two jars in build/libs that match z-api-*.jar. This is due to Spring Boot 2.5 no longer disabling the jar task by default. From the release notes:
The Spring Boot Gradle Plugin no longer automatically disables the standard Gradle jar and war tasks. Instead we now apply a classifier to those tasks.
If you prefer to disable those tasks, the reference documentation includes updated examples.
You could update your COPY command so that it doesn’t match the -plain.jar that’s now produced by the jar task. Alternatively, you could disable the jar task:
jar {
enabled = false
}
As #andy-wilkinson explained, the reason is that 2 jar files are generated by Gradle as
<appname>-0.0.1-SNAPSHOT.jar
<appname>-0.0.1-SNAPSHOT-plain.jar
If you prefer that the plain archive isn’t built at all, disable its task.
If you are using Kotlin with Gradle, add the following script to build.gradle.kts
tasks.named<Jar>("jar") {
enabled = false
}
Read more on https://docs.spring.io/spring-boot/docs/2.5.x/gradle-plugin/reference/htmlsingle/#packaging-executable.and-plain-archives

Maven Failsafe Integration Test Classpath

I have an spring application which reads properties file content from etcd server and then writes the content of that into applications properties file. After that I use that properties file to load my propertyManager.
Code implementation is done but when I try to create integration-tests, there is an small problem:
I use MyClass.class.getResource(configFilePath) to get URL of my properties file and since it points to a file inside of a JAR file while working integration tests. I can't write what I read from etcd server to my properties file since its in JAR file(under target) now.
I tried to add additionalClasspathElement ${project.build.directory}\conf to my classpath and use properties file inside of that folder but its not working.
Is there a way for me to change classpath of integration test via failsafe plugin?
Note: Springs etcd support is not want I want to use. I want to change my classpath when I run my integration 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?

Hot swap available by maven wrapper (mvnw)?

I added spring boot dev tool dependency in current Spring boot application, but when running the application by mvnw spring-boot:run It seems not recognized the change made in Java
I do use Eclipse to make the code change and enable automatically build. and refresh my code. So i think the latest .class file should be under /target directory
So does mvnw supports hot swap at all?

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