DevOps / Gradle8 Interview Questions
How does Gradle determine whether a task is up to date?
Gradle compares a task's declared inputs (source files, configuration properties, dependency files) and outputs (compiled classes, generated files) against a snapshot recorded the last time that task ran successfully. If every input and output matches the previous snapshot exactly, the task is considered up to date and skipped entirely, rather than executed and then discovered to have produced identical output.
tasks.register('generateReport') { inputs.file('data.csv') outputs.file('report.html') doLast { // generate report.html from data.csv } }
The comparison uses content hashing, not just file timestamps, so a file that's touched (timestamp changed) but has identical content still counts as unchanged. This only works, though, if a task's inputs and outputs are declared accurately — a custom task that reads a file without declaring it as an input can silently produce stale results, since Gradle has no way to know that file's changes should have invalidated the up-to-date check.
More Related questions...
