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' }
}
This plugin does not work well with the configuration cache. Using the example above:
- run
gradlew test
on a clean checkout oforigin/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 thata/blah
was added
- without configuration-cache ->
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.
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".
Plugin DSL javadoc. For requirements see spotless-changelog.