Spring Boot Gradle bootRun task default classpath and current working directory - spring-boot

I am going to test external config for application. What is default classpath and default working directory for Spring Boot Gradle bootRun task?
I didn't get in from:
http://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-running-your-application.html
https://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-gradle-plugin.html
UPDATE test with System.getProperty("user.dir") show that current directory is where Gradle is started.

Working directory is actually the module with Spring Boot project, which does not necessarily have to be the rootProject.
Classpath for bootRun is:
working directory (or Gradle project directory with Spring Boot)
main classes
runtime classpath
At least this is what seems to be the default when I debug the build (now easily possible with IntelliJ IDEA 2018.2).

Related

Hot reloading a multi-module spring boot application with gradle

I'm trying to convert a project from maven to gradle, but I'm having trouble getting hot reloading to work the same way. I can't show the actual project so I've created two identical very simple projects. One with maven one with gradle. These projects contain two modules:
project
|____api
|____lib
The /api module contains a spring-boot app which depends on code from the /lib module
In the maven project I can change code in either of these modules and recompile either with my IDE (intellij) or with the maven cli and spring-boot-devtools will hot reload the application. However in the gradle version it only successfully hot reloads code that has changed in the /api module.
From what I gathered this seems like a classpath issue. If you run gradle or maven in debug mode it prints out the classpath it passes when it starts the application. Maven includes <project_dir>/lib/target/classes/kotlin/main. However gradle only includes <project_dir>/lib/build/libs/lib.jar
I'm very new to gradle to I might have some of the build configuration messed up. Here are the two project repo's:
Maven: https://github.com/Perry-Olsson/mvn-hot-reload
Gradle: https://github.com/Perry-Olsson/gradle-hot-reload

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

Difference between Spring boot 2.5.0 generated *jar and *-plain.jar?

I upgraded my spring boot app to 2.5.0, then is app.jar and app-plain.jar is created by gradle.
I would like to the difference between these jars.
thanks
app.jar is the archive produced by the bootJar task. This is a Spring Boot fat jar that contains all of the module's dependencies as well as its classes and resources. It can be run using java -jar.
app-plain.jar is the archive produced by the jar task. This is a plain or standard jar file that contains only the module's classes and resources.
You can learn a bit more about this in the documentation for Spring Boot's Gradle plugin.

How to ship a Spring Boot app from a Gradle Multi Build project?

Let's say I have a Gradle Multi Project with 3 subprojects, 2 Spring Boot projects (auth and profile) and 1 Library project (commons).
The 2 Spring Boot projects include a dependency on the Library project: implementation project(":commons")
Actually, to run the 2 Spring Boot projects, I have to run this from the parent project:
gradlew auth:bootRun
gradlew profile:bootRun
If I run gradlew bootRun only, from each Spring Boot subproject, I get the Error like the :commons Library project is not found in the root project, which makes sense, because the :commons project is included only in the parent's settings.gradle file.
I have to push each Spring Boot subproject individually to Heroku.
How should I manage ?
I finally got it, just add this in each subproject's settings.gradle file, then build:
include ":commons"
project(':commons').projectDir = new File('../commons')

what is reason the spring boot application doesn't read application.properties file?

i have a maven project then i'm manually added a 'src/main/resources' directory and application.properties but it can't read the application.properties file;
How can i convert my maven project to spring boot project ?
You need to say your IDE that src/main/resources is a source folder.
Try a maven plugin (e.g. for Eclipse http://maven.apache.org/plugins-archives/maven-eclipse-plugin-2.8/eclipse-mojo.html),
do it manually
start your application using the maven spring-boot plugin
mvn spring-boot:run
http://docs.spring.io/spring-boot/docs/current/maven-plugin/usage.html

Resources