quarkusio/quarkus · error · GradleException
Failed to restore the timestamp of the file:
Error message
Failed to restore the timestamp of the file:
What it means
Thrown by the Quarkus Gradle plugin's CustomFileSystemOperations when it cannot set the last-modified time of a copied file back to the source file's timestamp. During timestamp-preserving copies/syncs the plugin records each copied file's source mtime and destination path, then replays those mtimes with Files.setLastModifiedTime; an IOException there is wrapped in this GradleException.
Source
Thrown at devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/util/CustomFileSystemOperations.java:198
}
copy.into(config.destination);
if (!config.includes.isEmpty()) {
copy.include(config.includes);
}
if (!config.excludes.isEmpty()) {
copy.exclude(config.excludes);
}
}
private static void restoreTimestamps(List<CopiedFileMetadata> copiedFilesMetadata) {
for (CopiedFileMetadata m : copiedFilesMetadata) {
try {
Files.setLastModifiedTime(m.destination(), m.sourceMtime());
} catch (IOException e) {
throw new GradleException("Failed to restore the timestamp of the file: " + m.destination(), e);
}
}
}
}
View on GitHub (pinned to e1c734241f)
Solutions
- Check ownership and write permissions on the destination file/directory; fix with chown/chmod or run Gradle as a user that owns the build output.
- Verify no external process (antivirus, sync client, IDE) is deleting or locking files in the output directory during the build.
- Clean the build (gradle clean or delete the output dir) to remove stale files with wrong ownership.
- Ensure the destination filesystem supports setting modification times (some network/overlay filesystems do not).
Example fix
// before: files copied into a root-owned dir
quarkusSync { into 'build/quarkus-app' }
// after: ensure the dir is writable before the task
/tasks.named('quarkusSync') { doFirst { def d = file('build/quarkus-app'); d.mkdirs(); assert d.canWrite() } }/ Defensive patterns
Strategy: try-catch
Validate before calling
// before the copy task
def dest = project.file('build/quarkus-app')
if (dest.exists() && !dest.canWrite()) throw new IllegalStateException("Output dir not writable: $dest")
if (dest.exists() && Files.getOwner(dest.toPath()).name != System.getProperty('user.name')) {
logger.warn('Output dir owned by another user; clean the build first')
} Try / catch
try {
copyPreservingTimestamps(spec)
} catch (GradleException e) {
def f = e.message.minus('Failed to restore the timestamp of the file: ')
def file = new File(f)
file.delete() // drop the unreadable/locked output and retry once
copyPreservingTimestamps(spec)
} Prevention
- Run all Gradle invocations (including IDE sync) as the same OS user.
- Exclude build/ directories from antivirus and file-sync tools.
- Run gradle clean after switching users or containers for the same workspace.
- Avoid output directories on filesystems that don't support mtime updates (some NFS/network mounts).
When it happens
Trigger: Files.setLastModifiedTime throws while iterating CopiedFileMetadata entries after a copyPreservingTimestamps or syncPreservingTimestamps call — typically because the destination file was deleted/moved mid-operation, the destination is read-only, or the process lacks write permission on the output directory.
Common situations: Running Gradle builds as different users (e.g. root-created files then non-root build), CI containers with restricted file ownership, antivirus/backup tools locking destination files, or read-only mounted build output directories.
Related errors
- Failed to persist extension descriptor
- Failed to persist
- Failed to collect project's classes in a temporary dir
- Failed to write Quarkus build configuration settings
- Failed to get source file mtime for
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/71c16c1d7d4a8543.
Report an issue: GitHub.