Reputation: 1612
Using parallel Gradle jobs on GitLab CI:
I'm receiving following random Gradle exception:
FAILURE: Build failed with an exception.
* What went wrong:
Could not create service of type ScriptPluginFactory using BuildScopeServices.createScriptPluginFactory().
> Could not create service of type ResourceSnapshotterCacheService using GradleUserHomeScopeServices.createResourceSnapshotterCacheService().
I use a docker
executor of gitlab-runner
without any GitLab CI caching. I use a Docker volume instead with Gradle cache pointing to that volume:
before_script:
- export GRADLE_USER_HOME=/pipelines/.gradle
There is no issue with access rights to the /pipelines
directory (so it's not duplicity of this question).
Simple, but annoying workaround to this issue is just to re-trigger the failed job manually - then it passes without any problem. Another workaround could to re-trigger the job automatically via the retry directive.
So, my question is: What is causing the job failure and how to solve it (without job re-triggering)?
Upvotes: 2
Views: 2377
Reputation: 1612
Root cause:
After some debugging (switches --stacktrace
and --info
), it's obvious that the root cause is that multiple Docker containers are sharing one Gradle cache on the host machine.
Caused by: org.gradle.cache.LockTimeoutException: Timeout waiting to lock file hash cache (/pipelines/.gradle/caches/4.10.2/fileHashes). It is currently in use by another Gradle instance.
Owner PID: 158
Our PID: 160
Owner Operation:
Our operation:
Lock file: /pipelines/.gradle/caches/4.10.2/fileHashes/fileHashes.lock
Solution:
There is still unsolved Gradle bug/feature: Let multiple containers share downloaded dependencies. Therefore I (re)implemented proper Gradle caching per each involved GitLab CI job (so, no shared cache 😢):
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
rpmClient:
stage: buildRpm
script:
- gradle clientRpm
cache:
paths:
- .gradle/caches
Upvotes: 5