skip to Main Content

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 /

2

Answers


  1. 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
    }
    
    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search