Caching gradle build artifacts/dependencies
-
I am currently leveraging caching of gradle dependency files to speed up performance between build/test stages. And while it appears based on logging that thousands of files are cached and restored between build/test, the stages still re-download all of the dependency artifacts anyway based on gradle debug output (
-i
). -
build
ends with.gradle/*
files being cached, andtest
begins with the cache being extracted. -
Dependency artifacts are downloaded to
/tmp
, and I have determined that that is governed by-Djava.io.tmpdir
, but those files appear to be deleted before gitlab-ci caches the files. I attempted to settmpdir
to a directory inside of$CI_PROJECT_DIR
, and then including that in the files list, but it is always empty. -
Local version of cache is used, not something uploaded to a shared cache server.
-
I need to figure out why gradle downloads all of the dependency artifacts after the cache has been restored.
-
What version are you on? Are you using self-managed or GitLab.com?
-
GitLab (Hint:
/help
): EE 13.6.4 self-managed -
Runner (Hint:
/admin/runners
): unk
-
GitLab (Hint:
-
gitlab-ci.yml:
stages:
- build
- test
variables:
GRADLE_OPTS: "-Dorg.gradle.daemon=false -Xmx1024m"
.cache:
cache:
key:
files:
- build.gradle
- libraries.gradle
paths:
- .gradle/cache
- .gradle/wrapper
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
- export JAVA_HOME=/usr/lib/jvm/jdk-11/
build-text:
extends: .cache
stage: build
image:
name: ...
artifacts:
paths:
- "**/build/**/*.jar"
expire_in: 1 week
script:
- /bin/sh $CI_PROJECT_DIR/gradlew --build-cache -i assemble
test-text:
extends: .cache
stage: test
image:
name: ...
script:
- /bin/sh $CI_PROJECT_DIR/gradlew -i test