Gradle "Could not create service of type ..." in CI
Gradle builds an internal service registry at startup. When one service fails to construct, usually because a cache under ~/.gradle is corrupt or a lock is stuck, the whole build aborts before any task runs.
What this error means
The build fails immediately with "Could not create service of type FileHasher using ..." or a similar service, pointing at a file in the Gradle caches.
FAILURE: Build failed with an exception.
* What went wrong:
Could not create service of type FileHasher using
GradleUserHomeScopeServices.createCachingFileHasher().
> Timeout waiting to lock file hash cache (/home/runner/.gradle/caches/8.7/fileHashes).Common causes
A corrupt or locked Gradle cache
A partially written cache under ~/.gradle/caches (from a killed build or a bad restore) prevents the service from initialising.
A version-mismatched cached artifact
A cache directory restored from a different Gradle version can be incompatible with the current one starting up.
How to fix it
Clear the affected cache and re-run
- Note the cache path in the "Could not create service" cause.
- Delete that cache subdirectory (or the whole
~/.gradle/caches). - Re-run so Gradle rebuilds a clean cache.
rm -rf ~/.gradle/caches/*/fileHashes
./gradlew build --no-daemonKey the cache by Gradle version
Include the Gradle version in the cache key so a restore never mixes incompatible cache formats.
- uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: gradle-${{ hashFiles('**/gradle-wrapper.properties') }}-${{ hashFiles('**/*.gradle*') }}How to prevent it
- Include the Gradle version in your cache key.
- Do not restore a
~/.gradlecache across Gradle major upgrades. - Use
--no-daemonso stale daemon state does not corrupt services.