gradle/gradle · error · CacheOpenException

Failed to initialize %s

Error message

Failed to initialize %s

What it means

FixedSharedModeCrossProcessCacheAccess opens a cache under a cross-process lock and runs the initialization action once while holding the exclusive lock. If the action still reports that initialization is required afterwards, this CacheOpenException is thrown with the cache display name, carrying the last underlying failure as the cause. It means the cache could not be brought into a usable state.

Source

Thrown at platforms/core-execution/persistent-cache/src/main/java/org/gradle/cache/internal/FixedSharedModeCrossProcessCacheAccess.java:100

                            if (rebuild) {
                                exclusiveLock.writeFile(new Runnable() {
                                    @Override
                                    public void run() {
                                        initializationAction.initialize(acquiredExclusiveLock);
                                    }
                                });
                            }
                        }
                    } finally {
                        if (exclusiveLock != null) {
                            exclusiveLock.close();
                        }
                    }
                    fileLock = lockManager.lock(lockTarget, lockOptions, cacheDisplayName);
                    rebuild = initializationAction.requiresInitialization(fileLock);
                }
                if (rebuild) {
                    throw new CacheOpenException(String.format("Failed to initialize %s", cacheDisplayName), latestException);
                }
            }
            onOpenAction.accept(fileLock);
        } catch (Exception e) {
            if (fileLock != null) {
                fileLock.close();
            }
            throw UncheckedException.throwAsUncheckedException(e);
        }
        this.fileLock = fileLock;
    }

    @Override
    public void close() {
        if (fileLock != null) {
            try {
                onCloseAction.accept(fileLock);
                fileLock.close();

View on GitHub (pinned to 534f27719b)

Solutions

  1. Read the cause (latestException) in the stack trace; it names the real underlying failure
  2. Run ./gradlew --stop, delete the affected cache directory, and retry the build
  3. Fix ownership/permissions and free disk space on the cache volume
  4. If caused by version mixing, separate GRADLE_USER_HOME per Gradle version
Defensive patterns

Strategy: try-catch

Validate before calling

File dir = new File(cacheDirPath);
if (!Files.isReadable(dir.toPath()) || !Files.isWritable(dir.toPath())) {
    throw new IllegalStateException("Cache directory not accessible: " + dir);
}

Try / catch

try {
    cacheAccess.open(); // FixedSharedModeCrossProcessCacheAccess
} catch (CacheOpenException e) {
    Throwable root = e.getCause(); // 'latestException': the real init failure
    // recover by invalidating the cache directory, then retry once
}

Prevention

When it happens

Trigger: The initialization action throws repeatedly while the cache opens: unreadable or deleted cache directory, corrupted state/properties files, permission or disk problems while wiping or writing initial state.

Common situations: Corrupted cache after a crashed build, permission/ownership changes on the cache dir, mixed Gradle versions sharing one GRADLE_USER_HOME, full disk.

Related errors


AI-assisted analysis of gradle/gradle@534f27719b (2026-08-22). Data as JSON: /api/errors/cf9be466a2364cee. Report an issue: GitHub.