diff --git a/subprojects/persistent-cache/src/main/java/org/gradle/cache/internal/FixedSharedModeCrossProcessCacheAccess.java b/subprojects/persistent-cache/src/main/java/org/gradle/cache/internal/FixedSharedModeCrossProcessCacheAccess.java index 5e1ba364469e..c8f517b2c6c2 100644 --- a/subprojects/persistent-cache/src/main/java/org/gradle/cache/internal/FixedSharedModeCrossProcessCacheAccess.java +++ b/subprojects/persistent-cache/src/main/java/org/gradle/cache/internal/FixedSharedModeCrossProcessCacheAccess.java @@ -78,11 +78,14 @@ public void open() { try { if (exclusiveLock != null) { final FileLock acquiredExclusiveLock = exclusiveLock; - exclusiveLock.writeFile(new Runnable() { - public void run() { - initializationAction.initialize(acquiredExclusiveLock); - } - }); + rebuild = initializationAction.requiresInitialization(acquiredExclusiveLock); + if (rebuild) { + exclusiveLock.writeFile(new Runnable() { + public void run() { + initializationAction.initialize(acquiredExclusiveLock); + } + }); + } } } finally { if (exclusiveLock != null) {