google / ksp

Kotlin Symbol Processing API
https://github.com/google/ksp
Apache License 2.0
2.83k stars 265 forks source link

Gradle daemons lock KSP-related JAR files on Windows #1040

Open NorbertSandor opened 2 years ago

NorbertSandor commented 2 years ago

I use KSP in a multi-platform multi-module project with Idea CE. (But currently KSP is applied only on one JVM project.) The processor implementation is in a separate project (project-processor), and it depends on another local project (project-annotations) containing the annotation class triggering my processor to be applied. When I try to build or clean the whole project, I often run into that the JAR file of project-annotations is locked and therefore cannot be deleted. After I stop all Gradle daemons using gradlew --stop and retry the build/clean then it always succeeds. So it seems that the build artifact of project-annotations is locked by a Gradle daemon(s) which executed my processor from project-processor - and not only during the build but for longer term. (I use Kotlin 1.7.10 and the latest compatible KSP plugin.)

Unable to delete directory '...\project-annotations\build' Failed to delete some children. This might happen because a process has files open or has its working directory set in the target directory.

Discussion: https://kotlinlang.slack.com/archives/C013BA8EQSE/p1657567571507389

I use Windows 11 and as someone noted this issue is probably present only on Windows.

iseki0 commented 1 year ago

I did some debug try to analyze what happended. In the KotlinCompileDaemon process, the java.util.zip.ZipFile.Source doesn't close the underlying RandomAccessFile that in zfile field. After a GC(I trigger it on visualvm), the problem solved. So, should we call System.gc after build?

iseki0 commented 1 year ago

I guess the ZipFile.Source is used by JVM self.

NorbertSandor commented 1 year ago

@iseki0 sorry, I somehow missed your valuable comment... Maybe could you please file the issue in the JDK issue tracker?

The problem is still present in Java 17 (I tried with KSP 1.8.21-1.0.11).

iseki0 commented 1 year ago

@iseki0 sorry, I somehow missed your valuable comment... Maybe could you please file the issue in the JDK issue tracker?

The problem is still present in Java 17 (I tried with KSP 1.8.21-1.0.11).

I will do this, even I can't find a solution.

NorbertSandor commented 1 year ago

As a workaround, I still (reguraly) use gradlew --stop to stop the Gradle daemons when this problem arise...

ianbrandt commented 10 months ago

Possibly related: