How can I ignore failure of an exec task?

I want to call git with an exec task:

task runGit(type: Exec) {
    ignoreExitValue = true
    commandLine 'git', 'log', '--pretty=format:git-revision=%h_%an_%ai', '-n1'
    doFirst {
        standardOutput = new FileOutputStream(new File(globalBuild, 'gitinfo.txt'))
    }
}

where ‘git’ may not be available (i.e. someone downloads the source package and does not need to have git installed). But the above task will cause the build to fail if ‘git’ is not in the PATH.

As a workaround, one can call “cmd.exe /c git…” but that only works on Windows.

Thanks and Best Regards, Felix

You might want to consider using a non-native Git implementation to aid in portability.

https://github.com/ajoberstar/gradle-git