Gradle configuration cache broken for spotlessCheck in latest v7.0.2
the spotlessCheck task seems to (indirectly) use the file .git/HEAD, as switching between branches causes a gradle configuration cache miss.
EG:
> git checkout test-branch
> gradle spotlessCheck
… (stores configuration cache)
> git checkout main
> gradle spotlessCheck
Calculating task graph as configuration cache cannot be reused because file '.git/HEAD' has changed.
spotless is configured as follows in the root level build.gradle.kts
spotless.apply {
kotlin {
target("src/**/*.kt”)
ktlint(libs.versions.ktlint.get())
}
}
This seems to be caused by JGit. The configuration cache report has the class org.eclipse.jgit.util.io.SilentFileInputStream accessing .git/HEAD and .git/config. Although this is occurinig within JGit, perhaps theres a call to JGit that can be wrapped in a ValueSource? Or perhaps there’s a configuration to change/disable parts of spotless to fix this?
This is the correct behavior if you are using ratchetFrom. I don't see it in your example above, any chance it's hiding in some other file?
Yes, double checked. To be confident, I’ve narrowed it down to a sample project available here: https://github.com/n-hass/spotless-2431-demo
Amazing, thanks for the reproducer! Good chance we'll learn something important from it.
Just occurred to me that a possible workaround would be using a non-git-aware line ending: https://github.com/diffplug/spotless/tree/main/plugin-gradle#line-endings-and-encodings-invisible-stuff
Thanks! Can confirm setting lineEndings = LineEnding.UNIX does fix the configuration cache miss in the sample project.