Skip to content
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

Automatically clear gradle configuration cache and retry on stale-cache failure #1209

Open
nedtwigg opened this issue May 13, 2022 · 2 comments

Comments

@nedtwigg
Copy link
Member

Anywhere we throw this exception:

private static GradleException cacheIsStale() {
return new GradleException("Spotless JVM-local cache is stale. Regenerate the cache with\n" +
" " + (FileSignature.machineIsWin() ? "rmdir /q /s" : "rm -rf") + " .gradle/configuration-cache\n" +
"To make this workaround obsolete, please upvote https://github.com/diffplug/spotless/issues/987");
}

We could instead just do the rm -rf ourselves and then use project.gradle.startParameter to reconstruct and execute the gradle invocation. (javadoc)

I think the tricky part is that you might have to launch a new JVM so that the .gradle/configuration-cache files aren't locked. It might also be tricky to reconstitute the exact command, but just an approximation with the same task names would be plenty.

This would definitely need to be gated behind something like:

spotless {
  autoRetry_issue_987 = true
}

No plan to implement this, but happy to merge a PR for it.

@nedtwigg nedtwigg changed the title Automatically clear gradle cache Automatically clear gradle configuration cache and retry on stale-cache failure May 13, 2022
@melix
Copy link

melix commented Mar 10, 2023

Deleting the configuration cache looks like a terrible idea to me.

@nedtwigg
Copy link
Member Author

nedtwigg commented Mar 10, 2023

Agreed! My ranked preferences:

  1. within-jvm configuration cache to allow fastest possible developer feedback loop
  2. within-jvm configuration cache that uses the custom-fancy-serialization as a default way to prove task isolation for parallel execution, and users can workaround this with something like JvmLocalCache
  3. allow tasks that don't support across-jvm serialization to mark themselves, and when those tasks are eligible for execution, then run the configuration phase without troubling users
  4. (last choice) the proposal in this issue, which is really (3) above implemented manually

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

No branches or pull requests

2 participants