Fanilog
05/09/2023, 1:22 PMFROM gradle:jdk19-jammy AS build
COPY --chown=gradle:gradle . /home/gradle/src
WORKDIR /home/gradle/src
RUN gradle buildFatJar --no-daemon
FROM openjdk:19
EXPOSE 8080
EXPOSE 8080:8080
RUN mkdir /app
COPY --from=build /home/gradle/src/build/libs/*.jar /app/app.jar
CMD ["java", "-jar", "/app/app.jar"]
Adam S
05/09/2023, 1:32 PM./gradlew clean --no-build-cache --no-configuration-cache buildFatJar
every time.
It’s probably downloading the Gradle wrapper every time too.
You could try introducing another layer that will initialise Gradle before you copy /home/gradle/src
, so that layer can be re-used. But it’s kind of tricky to do that because most of the caching will be specific to any source or build config changes, and it’s difficult to split them up into an ‘init Gradle’ step and a ‘build source’ step.
You could try copying the cache from your local machine into the container https://docs.gradle.org/current/userguide/dependency_resolution.html#sub:ephemeral-ci-cache. But that’s kind of tricky.
Personally I run the Gradle build on my machine and then copy the result into the Docker image. That way, Gradle can be optimised for my machine, re-use the caches, and the Docker image is simpler.Fanilog
05/09/2023, 1:54 PMFanilog
05/09/2023, 2:35 PMephemient
05/09/2023, 2:43 PMephemient
05/09/2023, 2:45 PM