How does the gradle know that the files of input or output has been changed or not?

Gradle Incremental Build will work if the input files and the output files of the task haven’t been changed. But I wonder how does the gradle know that? By the modification time of the file or other methods?

Details of how it works are described in the user guide.

I used hours to read the documentation, but still don’t know the answer to the simple question about how it internally works.

Can you give yes or no answer: “Is the modified input change detected by reading file modification metadata only?” (faster operation) If the answer is no, then I assume Gradle will read the whole file content and create finger print of it (slower operation).

Gradle documentation is good, but the target users are developers! They need detailed information how it works or they have to look source code. Because they think can I use built-in functionality or should I reinvent the wheel my own.

Which part of Incremental build do you think is not clear enough and not targeted at developers? It clearly answers your question in the first paragraph even. In the first two sentences even.

Ok, the documentation is correct “This fingerprint contains the paths of input files and a hash of the contents of each file”. Thanks!

Btw. Cache doesn’t work if input and output are the same file. So you can’t easily update a file. I make a workaround which is working: Input is the last modified of the file and the output is a regular file.

Yes, a task should never modify files in-place, but always have separate input and output files.
Otherwise the task can never be up-to-date, it cannot be cache properly, …
And if the in-place modified files are outputs of a different task, it is even worth and the action that is done should probably right away have been a doLast { ... } action of that task.