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

kspCaches don't work together with Gradle build cache #2042

Closed
oehme opened this issue Aug 21, 2024 · 5 comments · Fixed by #2055
Closed

kspCaches don't work together with Gradle build cache #2042

oehme opened this issue Aug 21, 2024 · 5 comments · Fixed by #2055

Comments

@oehme
Copy link

oehme commented Aug 21, 2024

The ksp task has a kspCaches directory which contains backups of generated classes. The following sequence of events will lead to stale outputs files and compile errors:

  1. Run an initial build
  2. Add an annotated class and run another build - Code is generated for that new class
  3. Remove the class again and run another build- This results in a Gradle cache hit for ksp, restoring the output of step 1., but the kspCaches directory is unchanged and still contains the backup of that class
  4. Make any incremental change in the source code and run another build - ksp now restores the class from step 2, even though its source file no longer exists - This class likely does not compile any more

The only fix at that point is to do a clean build to get rid of the caches.

Workaround: I've marked the kspCaches directory for each ksp task as localState in our build, so Gradle deletes it on a cache hit.

Tested with 1.9.25-1.0.20

@ansman
Copy link
Contributor

ansman commented Aug 23, 2024

I am able to reproduce this in a test case. I will attempt a fix.

@ting-yuan Would it be OK to mark the kspCaches as local state as a fix?

@ansman
Copy link
Contributor

ansman commented Aug 23, 2024

I can confirm that marking the directory as local state does indeed work.

@oehme Have you noticed any issues with marking it as local state?

@oehme
Copy link
Author

oehme commented Aug 23, 2024

I assume that deleting them would make the next build non-incremental? That would be the main downside. I've noticed no other issues.

The alternative would be mark the caches as an output, so they get restored together with the classes they belong to. Then the next build could work incrementally again. For that to work, the caches need to be portable across machines (no absolute paths etc.). I didn't try it, because I didn't know what those caches contain exactly.

ansman added a commit to ansman/ksp that referenced this issue Aug 24, 2024
Without this change, the task's caches will be in an incorrect state and
the next incremental run can lead to compile errors.

Now the caches have been marked as local state and Gradle will remove
them when the task is restored from the build cache.

This fixes google#2042
@ansman
Copy link
Contributor

ansman commented Aug 24, 2024

@oehme Thanks for the repro, I implemented a fix in #2055

@oehme
Copy link
Author

oehme commented Aug 24, 2024

Thanks!

github-actions bot pushed a commit that referenced this issue Sep 5, 2024
Without this change, the task's caches will be in an incorrect state and
the next incremental run can lead to compile errors.

Now the caches have been marked as local state and Gradle will remove
them when the task is restored from the build cache.

This fixes #2042

(cherry picked from commit 3f31c10)
github-actions bot pushed a commit that referenced this issue Sep 5, 2024
Without this change, the task's caches will be in an incorrect state and
the next incremental run can lead to compile errors.

Now the caches have been marked as local state and Gradle will remove
them when the task is restored from the build cache.

This fixes #2042

(cherry picked from commit 3f31c10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants