Search code examples
groovygradlediffbuild-process

How to diff files/folders in Gradle?


I need to write a script in Gradle that takes as an input 2 folders. Both folders contain <1000 files (mostly images) with reasonably similar structure. The output should be a list of files that changed and what kind of difference it is (added file/deleted file/changed file).

Edit: Heres a sample script https://gist.github.com/igormukhin/71d780c4274336eeb297 . The only problem is that it compares by timestamp.


Solution

  • I have recently coded up something similar to what you are asking for: DirectoryDifferenceCollector; however, it actually compares the contents of the files (as a hash) and not the timestamp. I would be willing to update it to accept a configurable strategy if that would suit your needs, or you can just use the concepts involved.

    Basically it scans both directories and determines the missing files in both A and B and then it also determines which files are common to both directories, but have different content.

    The results are collected in a DirectoryDifference object with the respective file paths for each category.