Answers: <p>There is currently an issue open to share Gradle cache between containers:</p>
  
  <p><a href="https://github.com/gradle/gradle/issues/851" rel="nofollow noreferrer">https://github.com/gradle/gradle/issues/851</a></p>
  
  <p>I think the best solution at the moment is to bake as many dependencies in to the Docker image as possible, and then use a volume to share between sequential builds, limiting it to one concurrent build per host. You can mount the cache on to the host with a docker-compose.yml like so:</p>
  
  <pre><code>version: '3'
  services:
    gradle:
      image: gradle:4.0.1-jdk8-alpine  # I'd suggest using this as a base to build your own Gradle image with dependencies baked in
      working_dir: /usr/src/app
      volumes:
        - ./:/usr/src/app:Z
        - ./.gradle:/home/gradle/.gradle:Z
  </code></pre>
  
  <p>Alternatively, another solution would be to look at network-level caching e.g. Squid.</p>
  
Answers: CC BY-SA 3.0
Answers: 2017-10-03T11:26:54.033Z
Answers: 2017-10-03T11:26:54.033Z
Answers: user2640621
Body: <p>I have a multi-branch setup on Jenkins for my Gradle project. I would like to be efficient in terms of performance and cost as well (money!). Meaning, if would like to build my project many times, for different branches, commits, in parallel. For that I'm thinking about having everything inside of containers, but I'm not sure if my containers would share the libraries resolved by gradle. Moreover, I don't want to resolve dependencies for every time I bring them up, it would be time consuming and network usage as well. </p>
  
  <p>Or I'm thinking about deploying a simple vm with Ansible and run my builds from there, making this whole process simpler. </p>
  
  <p>So I wonder which approach would is better? Anyone faced a similar issue? Does someone has any benchmark to share? </p>
  
Tags: <docker><ansible><build-pipeline><gradle>
Title: Multiple gradle builds with docker
UserDisplayName: Valter Silva
ThreadText: # Multiple gradle builds with docker
  
  (Asked by: username_0 on 2017-09-28)
  
  I have a multi-branch setup on Jenkins for my Gradle project. I would like to be efficient in terms of performance and cost as well (money!). Meaning, if would like to build my project many times, for different branches, commits, in parallel. For that I'm thinking about having everything inside of containers, but I'm not sure if my containers would share the libraries resolved by gradle. Moreover, I don't want to resolve dependencies for every time I bring them up, it would be time consuming and network usage as well.
  
  Or I'm thinking about deploying a simple vm with Ansible and run my builds from there, making this whole process simpler.
  
  So I wonder which approach would is better? Anyone faced a similar issue? Does someone has any benchmark to share?
  
  **Tags:** docker, ansible, build-pipeline, gradle
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-10-03. Score: 3
  
  There is currently an issue open to share Gradle cache between containers:
  
  <https://github.com/gradle/gradle/issues/851>
  
  I think the best solution at the moment is to bake as many dependencies in to the Docker image as possible, and then use a volume to share between sequential builds, limiting it to one concurrent build per host. You can mount the cache on to the host with a docker-compose.yml like so:
  
  ```
  version: '3'
  services:
    gradle:
      image: gradle:4.0.1-jdk8-alpine  # I'd suggest using this as a base to build your own Gradle image with dependencies baked in
      working_dir: /usr/src/app
      volumes:
        - ./:/usr/src/app:Z
        - ./.gradle:/home/gradle/.gradle:Z
  
  ```
  
  Alternatively, another solution would be to look at network-level caching e.g. Squid.
  
  
  ---
  
  