Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to share gradle cache with docker containers

Tags:

docker

gradle

We run gradle builds within docker containers (the reason for that is the build requires software we don't want to install on the host; node, wine etc. Not even java or gradle is installed on the host).

Launching each container with an empty cache is annoying slow.

I've set up gradle-4.0's http build cache. That avoided the need to java-compile in most cases. The performance gain is though quite low, because build-time is dominated by downloading dependencies. gradlew --parallel helped to mitigate that a bit, but to really boost the build, downloading should be avoided altogether.

Sharing ~/.gradle as a docker volume is problematic, because it will cause contention when containers run in parallel (https://github.com/gradle/gradle/issues/851).

So, what else can be done to avoid downloading the same artifacts over and over again?

like image 351
Frank Neblung Avatar asked Jul 07 '17 10:07

Frank Neblung


People also ask

Does Gradle allow share build cache?

The build cache allows you to share and reuse unchanged build and test outputs across the team. This speeds up local and CI builds since cycles are not wasted re-building components that are unaffected by new code changes. NOTE: Gradle Enterprise Build Cache supports both Gradle and Maven build tool environments.

How do I access Gradle cache?

cd %userprofile%\. gradle\caches\modules-2\files-2.1 — a short command to locate to this directory on Windows.

How do I cache Gradle dependencies?

The Gradle dependency cache consists of two storage types located under GRADLE_USER_HOME/caches : A file-based store of downloaded artifacts, including binaries like jars as well as raw downloaded meta-data like POM files and Ivy files.


1 Answers

While it is problematic to share gradle caches from containers running in parallel, it is absolutely OK to reuse gradle caches when containers run sequentially. Builds that are launched by jenkins run sequentially.

Jenkins builds can be sped up by using a docker volume for the .gradle folder. The only drawback is, that each job requires its own volume.

like image 98
Frank Neblung Avatar answered Sep 29 '22 02:09

Frank Neblung