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

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

Related

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.

Use java S2I for spring boot app with gradle build in openshift

How to get started with java S2I build for spring boot application with Gradle build?
Please suggest me any Json/yml file needs to be imported to get started.
Here is a whole repo - https://github.com/dsevost/gradle-s2i - with a Dockerfile to build a S2I gradle builder image, and a template to build applications on top of it.
Perhaps it is worth noting the BUILDER parameter in the template with possible values of 'Gradle' or 'Maven'. According to the assemble script, it will build a gradle project even when both pom.xml and build.gradle are present in the project directory.
I haven't tried it myself but I glanced over the template and it looks OK...assuming the image and S2I scripts are functional.

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?

Use of spring-boot-maven-plugin

While creating a spring boot project I define property in pom.xml as <packaging>war</packaging> with which I can create a war and thereafter deploy the war into server maybe tomcat or WAS.
But I came across a plugin named spring-boot-maven-plugin whose documentation states that it's use is to package executable jar or war archives and run an application in-place.
My query is why do we need this at all ?
If my packaging can tell me what to create and then can deploy it to run, what is the used of this plugin.
I am trying to understand a new project so wanted to be sure that every line makes sense
The maven plugin will create an "executable" archive. In the case of the war packaging, you would be able to execute your app with java -jar my-app.war. If you intend to deploy your Spring Boot application in an existing Servlet container, then this plugin is, indeed, not necessary.
The maven plugin does more things like running your app from the shell or creating build information.
Check the documentation
The Spring Boot Maven Plugin provides Spring Boot support in Apache Maven, letting you package executable jar or war archives and run an application “in-place”.
Refer this - https://www.javaguides.net/2019/02/use-of-spring-boot-maven-plugin-with.html

How to generate executable scripts using spring boot maven plugin

Using spring boot maven plugin we are able to generate executable jars. And we can execute the jar using java -jar ...
In spring boot there is another option for installation . This generates the jar which can be added in init.d.
But is it possible to generate a sh|cmd file which can be used to start|stop|restart spring boot applications?
The executable true flag to create a 'fully executable’ jar actually pre-pends a shell script into the beginning of the jar.
It works outside init.d too. Try this:
./myapp.jar start

Resources