4

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?

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.