Gradle: how to show diff between 2 commits in a task?

How to write a gradle task that shows the difference between 2 commits in git and export the difference in a txt file?

I tried to create the task below but the task doesn’t seem to export into a txt file.

task diffLiterals() {
   
  description = 'get the difference between 2 commits in the literals.csv'
  def cmd = 'git diff HEAD^  HEAD --no-ext-diff model/localizations/literals-en.csv > test.txt'
  def diffFile = cmd.execute()
   
}

Running the git command itself in a terminal works fine though.

git diff HEAD^ HEAD --no-ext-diff  model/localizations/literals-en.csv > diff.txt

You might want to look into the Gradle Git plugin. It uses a pure Java Git client (JGit) so you can avoid all the nastiness of shelling out to the command line.

And as for why your task is not working, it’s because it’s not declaring any action.

You need to write
task diffLiterals()<< {

}