Skip to content

Gradle configuration cache broken for spotlessCheck in latest v7.0.2 #2431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
n-hass opened this issue Feb 24, 2025 · 4 comments
Open

Gradle configuration cache broken for spotlessCheck in latest v7.0.2 #2431

n-hass opened this issue Feb 24, 2025 · 4 comments
Labels

Comments

@n-hass
Copy link

n-hass commented Feb 24, 2025

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?

@nedtwigg
Copy link
Member

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?

@n-hass
Copy link
Author

n-hass commented Feb 25, 2025

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

@nedtwigg
Copy link
Member

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

@n-hass
Copy link
Author

n-hass commented Feb 26, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants