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

Incremental compilation fails with "Number of loaded files in snapshots differs" #1280

Closed
graemerocher opened this issue Jan 23, 2023 · 41 comments · Fixed by #1282, android/nowinandroid#666 or #2401
Assignees
Labels
bug Something isn't working P1 major features or blocking bugs
Milestone

Comments

@graemerocher
Copy link

We are building support for KSP in Micronaut (a popular Java/Kotlin framework). The initial implementation is done but it fails with KSP incremental compilation enabled with an error "Number of loaded files in snapshots differs" on the second compile:

./gradlew test
> Task :kspKotlin FAILED

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':kspKotlin'.
> Number of loaded files in snapshots differs. Reported changed files: []

To reproduce download this example project and run ./gradlew cTK twice.

ksp-test2.zip

@SimonMarquis
Copy link

👋 This issue popped up again since 1.8.20-Beta-1.0.9.

Here is an example with 1.8.20-RC-1.0.9 on the android/nowinandroid project:
https://github.com/SimonMarquis/nowinandroid/actions/runs/4409825508/jobs/7726595603#step:9:1881

Should we create a new issue?

@neetopia neetopia reopened this Mar 14, 2023
@neetopia neetopia modified the milestones: 1.0.9, 1.0.10 Mar 14, 2023
@neetopia neetopia added bug Something isn't working P1 major features or blocking bugs labels Mar 20, 2023
@neetopia neetopia assigned neetopia and unassigned ting-yuan Mar 20, 2023
@neetopia
Copy link
Contributor

@SimonMarquis I can't reproduce the bug consistently with a locally checked out repository, can you verify on your side with a snapshot build 1.8.20-RC-1.0.10-SNAPSHOT from repository https://oss.sonatype.org/content/repositories/snapshots/?

@neetopia
Copy link
Contributor

for context, the snapshot contains fix from #1350 which I anticipate to fix

@SimonMarquis
Copy link

Sorry for not being able to test this, I did not found enough time to test it yet.
Though it still happens on Kotlin 1.8.20 and KSP 1.8.20-1.0.10.
https://github.com/SimonMarquis/nowinandroid/actions/runs/4600305482/jobs/8126733329#step:9:2079

It might very well be an issue with the non-statble (non-compatible?) Compose compiler 1.4.4-dev-k1.8.20-RC-88d9f3a8232.

@ZacSweers
Copy link
Contributor

@neetopia did #1350 make it into 1.8.20-1.0.10? I'm still reproducing this in that release now in slackhq/circuit#454.

100% reproducible with the below steps

  1. run ./gradlew check
  2. make a small change to a source test file, such as adding a println in PetListSnapshotTest.kt
  3. run ./gradlew check again
  4. 💥

@neetopia
Copy link
Contributor

neetopia commented Apr 3, 2023

yes #1350 was included in the release, but does not seem to fix the issue.

@neetopia
Copy link
Contributor

neetopia commented Apr 5, 2023

I was able to reproduce @ZacSweers 's repro, but after I deleted both $HOME/.gradle/caches and project's .gradle/configuration-cache, and tries to do the reproduce steps again, it seems not reproducing anymore..

@Enaium
Copy link

Enaium commented Apr 6, 2023

I also encountered this problem when using 1.8.20-1.0.10, Need to run gradle clean before run the project each time

@neetopia
Copy link
Contributor

neetopia commented Apr 6, 2023

@Enaium can you give me a reproduce project? I am not able to reproduce @ZacSweers 's sample anymore after manually removing home caches and project configuration caches. Right now I am not sure if that has anything to do with remote cache.

@ZacSweers
Copy link
Contributor

I'm able to reproduce it 100%. Maybe try building once with 1.8.10 and then 1.8.20?

@neetopia
Copy link
Contributor

neetopia commented Apr 6, 2023

7168  gco main
 7169  less gradle.properties
 7170  less gradle/libs.versions.toml
 7171  ./gradlew check
 7172  git log
 7173  gco z/kotlin1820
 7174  ./gradlew check
 7175  vi samples/star/src/test/kotlin/com/slack/circuit/star/petlist/PetListSnapshotTest.kt
 7176  ./gradlew check

yeah that was what I did try to reproduce. I was able to reproduce 100% as well before deleting both local caches. I have another laptop not with me that can still reproduce 100% as I did not try removing caches on that laptop.

@Enaium
Copy link

Enaium commented Apr 7, 2023

@Enaium can you give me a reproduce project? I am not able to reproduce @ZacSweers 's sample anymore after manually removing home caches and project configuration caches. Right now I am not sure if that has anything to do with remote cache.

https://github.com/Enaium/jimmer-sql-kt-vertx
But the project is using 1.8.10-1.0.9 now

@svenjacobs
Copy link

I'm facing the same issue since upgrading to Kotlin 1.8.20 and KSP 1.8.20-1.0.10. Interestingly I cannot reproduce this on my local machine but 100% in a GitHub Actions workflow, although the workspace is absolutely clean with no caches (I disabled the cache action to ensure this).

@G00fY2
Copy link

G00fY2 commented Apr 13, 2023

Same issue here. We run our Jenkins CI builds without any caching in place, so 100% clean build each time. After updating to Kotlin 1.8.20, KSP 1.8.20-1.0.10 and Compose compiler 1.4.5 we also see this build error.

@neetopia
Copy link
Contributor

Hi all, thanks for the reports, I've pushed a fix in #1363 and it is now available as 1.8.20-1.0.11-SNAPSHOT in snapshot repository, you can add

  maven {
    url = uri("https://oss.sonatype.org/content/repositories/snapshots")
  }

in your project and try out this snapshot to see if it resolves your issue, if everything looks good I will do a hot fix release soon to address this issue.

@jeffdcamp
Copy link

So glad I found this issue.... we couldn't run after updating to Kotlin 1.8.20, KSP 1.8.20-1.0.10 and Compose compiler 1.4.5.

We just tried the 1.8.20-1.0.11-SNAPSHOT and all is working for us! (hope 1.8.20-1.0.11 releases soon :) )

@hansenji
Copy link

This fixed it for me as well in my CI/CD running Unit Tests

@masztalski
Copy link

Seems to work for me also. Waiting for final build

@neetopia
Copy link
Contributor

Cool, hot-fix release should be available on Monday.

@svenjacobs
Copy link

I can also confirm that 1.8.20-1.0.11-SNAPSHOT fixes the problem 🎉 Thank you!

@lihenggui
Copy link

Cool, wait for the hot fix!

@neetopia
Copy link
Contributor

hot fix is released as 1.8.20-1.0.11, closing this issue.

@rschattauer
Copy link

@neetopia I am still facing this issue with 1.8.22-1.0.11

@neetopia
Copy link
Contributor

neetopia commented Jul 5, 2023

@rschattauer Can you please give me a reproduce repo for this issue in 1.8.22-1.0.11? Thanks.

@rschattauer
Copy link

@neetopia it's kind of rough, as locally I have 0 issues, while our CI (jenkins) throws 100% of the time on the branch where I update that

@pengdev
Copy link

pengdev commented Jul 12, 2023

Hey @neetopia I'm facing the same issue with 1.7.20-1.0.8 release, as we can not bump kotlin version in our project, is it possible to port the fix to the 1.7.20 kotlin release? Or could you suggest any workarounds that we can apply to our project to bypass this issue? Thanks in advance!

@neetopia
Copy link
Contributor

We can't do a back port release, would disable incremental to mitigate this issue work for you?

@pengdev
Copy link

pengdev commented Jul 12, 2023

@neetopia Thanks for the suggestion, I did try to disable incremental and it did help mitigate this issue. I think we are ok with the workaround for now 👍

@erikghonyan
Copy link

erikghonyan commented Mar 27, 2025

We're seeing this issue again on 2.1.10-1.0.31 as well as 2.1.20-1.0.31 and 2.1.20-1.0.32. It works on 2.1.10-1.0.30.

In our case the "Reported changed files" list is not empty though, it's a lot of (100+) ~/.gradle/caches/8.13/transforms/[hash]/transformed/output.bin files with different hashes. This is on Gradle 8.13

@liujigang
Copy link

ksp:2.1.20-1.0.32 and gradle: 8.11.1 ,issue again

@speedclaud
Copy link

speedclaud commented Apr 3, 2025

@liujigang Yes, I'm having the same issue with these versions after bumping:

com.google.devtools.ksp: 2.1.20-1.0.32
com.android.tools.build:gradle:8.9.1
gradle:8.11.1
Android Studio Narwhal | 2025.1.1 Nightly 2025-04-01
Build #AI-251.23774.16.2511.13296593, built on April 1, 2025
Runtime version: 21.0.6+-13119726-b895.91 aarch64 (JCEF 122.1.9)
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.lwawt.macosx.LWCToolkit
macOS 15.3.2
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Memory: 8192M
Cores: 12
Metal Rendering is ON
Registry:
  debugger.new.tool.window.layout=true
  ide.experimental.ui=true
  terminal.new.ui=true
  com.android.studio.ml.activeModel=com.android.studio.ml.AidaModel
Non-Bundled Plugins:
  com.intellij.marketplace (251.23774.216)
  net.seesharpsoft.intellij.plugins.file-preview (1.6.4)
  com.mallowigi.colorHighlighter (18.1.0)
  io.github.composegears.valkyrie (0.13.0)
  zielu.gittoolbox (600.1.0+243)

@Micoder-dev
Copy link

Same issue popped up again.
id("com.google.devtools.ksp") version "2.1.20-1.0.32" apply false

@luboganev
Copy link

I'm also experiencing the same issue again in Android Studio stable

  • Android Studio Meerkat | 2024.3.1 Patch 1.
  • Kotlin 2.1.20
  • KSP 2.1.20-1.0.32
  • AGP 8.9.1
  • gradle-8.13
  • openjdk 17.0.14 2025-01-21
  • Mac Apple M4 Pro
  • macOS 15.4 (24E248)

The only current "fix" for me is downgrade:

  • Downgrade to KSP 2.1.10-1.0.30
  • Downgrade to Kotlin 2.1.10

@Micoder-dev
Copy link

@luboganev Yeah, It worked Thanks..!

@marianeum
Copy link

Is anybody able to create a project to reproduce the issue? We're affected as well, but I couldn't reproduce it on a small sample project. It might be worth creating a new issue with that as I'm not sure this is monitored anymore.

@luboganev
Copy link

@marianeum

I have some updates. I have started as well a fresh project, but couldn't reproduce the issue. Than started adding more and more stuff to it until it failed.

In my actual project I use ksp for everything besides Retrofit (since AFAIK Retrofit doesn't have KSP yet). At the moment I have added Retrofit and kapt, I have started observing the issue. So it's something that goes wrong between Kapt and ksp. Here is the repository to reproduce it. If you remove the kapt stuff everything is fine, but if you add it, then 2 consecutive builds always fail if no clean is done between:

https://github.com/luboganev/kspandkaptissue

@ting-yuan , what would you recommend we do from here? Thanks a lot!

@ting-yuan ting-yuan reopened this Apr 4, 2025
@ting-yuan
Copy link
Collaborator

While I'm still investigating this issue, it seems that it only happens on KSP1 but not KSP2. Could you try KSP2 as a workaround and let me know how it works?

@luboganev
Copy link

@ting-yuan

I can confirm that the proposed workaround resolves the issue. I have implemented this in the following branch of the sample project:
https://github.com/luboganev/kspandkaptissue/tree/fix/enable-ksp2-workaround

Thank you very much investigation and the support!

@luboganev
Copy link

@ting-yuan , unfortunately, I was too quick to celebrate. Activating ksp2 now is suffering from this issue:
#2177

@consp1racy
Copy link

Don't close this. Ksp2 is a no go, it's painfully slow.

@G00fY2
Copy link

G00fY2 commented Apr 8, 2025

KSP2 is not supported by dagger/hilt yet. So not an option for now: google/dagger#2349 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P1 major features or blocking bugs
Projects
None yet