Skip to content

Latest commit

 

History

History
69 lines (54 loc) · 4.32 KB

IF_GIT_DIFF.md

File metadata and controls

69 lines (54 loc) · 4.32 KB

If Git Diff

Gradle plugin Maven central Apache 2.0

Changelog Javadoc Live chat CircleCI

This plugin can be applied in settings.gradle or build.gradle, and it lets you execute a block of code contingent on whether there are changes in the given folder relative to a given baseline git ref.

plugins {
  id 'com.diffplug.if-git-diff'
}
ifGitDiff {
  baseline 'origin/main' // default value
  inFolder 'a', { include 'a' }
  inFolder 'b', { include 'b' }
}

Limitations

This plugin does not work well with the configuration cache. Using the example above:

  • run gradlew test on a clean checkout of origin/main, and you would see that :test ran but :a:test and :b:test did not; so far so good.
  • now add a file a/blah
  • now if you run gradlew test
    • without configuration-cache -> :test and :a:test -> good!
    • with configuration-cache -> only :test -> bad, cached configuration doesn't know that a/blah was added

A different approach which could work with configuration-cache is to mark tasks as up-to-date based on git status, see the GitDiffUpToDatePlugin for that.

Roadmap

This plugin was built to solve a fairly specific problem in the Spotless build. It is packaged with spotless-changelog because it's vaguely related, and it might make sense someday for spotless-changelog to assert "if files changed in X dir, then changelog Y must be updated".

Reference

Plugin DSL javadoc. For requirements see spotless-changelog.

Acknowledgments