Search code examples
javadockergradledockerfilegradle-dependencies

How to make Gradle cache persistent through Docker containers?


I have a Java(Gradle) project. A docker image is built in CI using Dockerfile:

FROM gradle:6.8.3-jdk11
COPY --chown=gradle:gradle . /home/gradle/app
WORKDIR /home/gradle/app
RUN gradle compileTestJava

Although gradle compileTestJava downloads all dependencies, when the container is run from the image, gradle cache turns out to be empty and all dependencies are being redownloaded.

How can I make gradle cache attached to the image so it would be used in containers?


Solution

  • It appeared that .gradle folder is set as a VOLUME in gradle:6.8.3-jdk11 which prevents cache from being saved in the image.

    The solution was to create a custom base gradle image without a volume.