title: Slow gradle build in Docker. Caching gradle build
body: <p>I am doing university project where we need to run multiple Spring Boot applications at once.</p>
  
  <p>I had already configured multi-stage build with gradle docker image and then run app in openjdk:jre image.</p>
  
  <p>Here is my Dockerfile:</p>
  
  <pre><code>FROM gradle:5.3.0-jdk11-slim as builder
  USER root
  WORKDIR /usr/src/java-code
  COPY . /usr/src/java-code/
  
  RUN gradle bootJar
  
  FROM openjdk:11-jre-slim
  EXPOSE 8080
  WORKDIR /usr/src/java-app
  COPY --from=builder /usr/src/java-code/build/libs/*.jar ./app.jar
  ENTRYPOINT ["java", "-jar", "app.jar"]
  </code></pre>
  
  <p>I am building and running everything with docker-compose. Part of docker-compose:</p>
  
  <pre><code> website_server:
      build: website-server
      image: website-server:latest
      container_name: "website-server"
      ports:
        - "81:8080"
  </code></pre>
  
  <p>Of course first build take ages. Docker is pulling all it's dependencies. And I am okay with that. </p>
  
  <p>Everything is working ok for now but every little change in code causes around 1 min build time for one app.</p>
  
  <p>Part of build log: <code>docker-compose up --build</code></p>
  
  <pre><code>Step 1/10 : FROM gradle:5.3.0-jdk11-slim as builder
   ---&gt; 668e92a5b906
  Step 2/10 : USER root
   ---&gt; Using cache
   ---&gt; dac9a962d8b6
  Step 3/10 : WORKDIR /usr/src/java-code
   ---&gt; Using cache
   ---&gt; e3f4528347f1
  Step 4/10 : COPY . /usr/src/java-code/
   ---&gt; Using cache
   ---&gt; 52b136a280a2
  Step 5/10 : RUN gradle bootJar
   ---&gt; Running in 88a5ac812ac8
  
  Welcome to Gradle 5.3!
  
  Here are the highlights of this release:
   - Feature variants AKA "optional dependencies"
   - Type-safe accessors in Kotlin precompiled script plugins
   - Gradle Module Metadata 1.0
  
  For more details see https://docs.gradle.org/5.3/release-notes.html
  
  Starting a Gradle Daemon (subsequent builds will be faster)
  &gt; Task :compileJava
  &gt; Task :processResources
  &gt; Task :classes
  &gt; Task :bootJar
  
  BUILD SUCCESSFUL in 48s
  3 actionable tasks: 3 executed
  Removing intermediate container 88a5ac812ac8
   ---&gt; 4f9beba838ed
  Step 6/10 : FROM openjdk:11-jre-slim
   ---&gt; 0e452dba629c
  Step 7/10 : EXPOSE 8080
   ---&gt; Using cache
   ---&gt; d5519e55d690
  Step 8/10 : WORKDIR /usr/src/java-app
   ---&gt; Using cache
   ---&gt; 196f1321db2c
  Step 9/10 : COPY --from=builder /usr/src/java-code/build/libs/*.jar ./app.jar
   ---&gt; d101eefa2487
  Step 10/10 : ENTRYPOINT ["java", "-jar", "app.jar"]
   ---&gt; Running in ad02f0497c8f
  Removing intermediate container ad02f0497c8f
   ---&gt; 0c63eeef8c8e
  Successfully built 0c63eeef8c8e
  Successfully tagged website-server:latest
  </code></pre>
  
  <p>Every time it freezes after <code>Starting a Gradle Daemon (subsequent builds will be faster)</code></p>
  
  <p>I was thinking about adding volume with cached gradle dependencies but I don't know if that is core of the problem. Also i could't find good examples for that.</p>
  
  <p>Is there any way to speed up the build?</p>