spotless icon indicating copy to clipboard operation
spotless copied to clipboard

Gradle configuration cache broken for spotlessCheck in latest v7.0.2

Open n-hass opened this issue 1 year ago • 4 comments

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?

n-hass avatar Feb 24 '25 05:02 n-hass

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?

nedtwigg avatar Feb 24 '25 16:02 nedtwigg

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

n-hass avatar Feb 25 '25 03:02 n-hass

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

nedtwigg avatar Feb 25 '25 18:02 nedtwigg

Thanks! Can confirm setting lineEndings = LineEnding.UNIX does fix the configuration cache miss in the sample project.

n-hass avatar Feb 26 '25 04:02 n-hass