Skip to content
Latchkey

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.

Gradle
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

  1. Note the cache path in the "Could not create service" cause.
  2. Delete that cache subdirectory (or the whole ~/.gradle/caches).
  3. Re-run so Gradle rebuilds a clean cache.
Terminal
rm -rf ~/.gradle/caches/*/fileHashes
./gradlew build --no-daemon

Key the cache by Gradle version

Include the Gradle version in the cache key so a restore never mixes incompatible cache formats.

.github/workflows/ci.yml
- 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 ~/.gradle cache across Gradle major upgrades.
  • Use --no-daemon so stale daemon state does not corrupt services.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →