Hello! I'm having approximately the same error as ...
# ksp
d
Hello! I'm having approximately the same error as the following post on StackOverflow: https://stackoverflow.com/questions/79311813/kotlin-ksp-how-to-generate-aggregating-output-files I'm trying to, in a symbol processor, get every class implementing a specific interface, create a single new file and to it add a line for each class implementing that interface. I open the file once during processing, passing
containingFile
for every
KSClassDeclaration
I find that matches my criterion, and setting the
aggregating
flag to true. I also wrap each
KSClassDeclaration
in a
KSTopDownVisitor
to write my data. As far as I understand KSP, this should be everything necessary to not reprocess the classes in future runs, but I can see that it runs multiple times and as soon as it does it causes a
fileAlreadExistsException
. Any ideas?
d
That Stack Overflow question is very hard to parse, but a common cause of
FileAlreadyExistsException
is attempting to write the file even when there are no relevant symbols found. The pseudocode for a simple processor doing what you described should be something like: 1. Get all classes implementing a specific interface 2. Process these classes somehow into a single collection of data for output 3. Only in the case where is data from step 2, write the file once based on the collection There are solutions for more advanced use cases if you search the chat for
FileAlreadyExistsException
including writing in
finish()
and generating dummy outputs.
j
We ran into https://github.com/google/ksp/issues/1993 while developing our processors and implemented the provided workaround to get around this issue. It's not a catch all & could be another issue in your code (as David has pointed out) but give it a try?
👍 1
d
Sorry for the late reply, but for posterity and other users I managed to implement what David suggested and it works perfectly.
👍 1