Hello! I have an issue but I am not sure if this i...
# ksp
v
Hello! I have an issue but I am not sure if this is related with the KSP. I have a processor that runs and generates some classes. From time to time it stops working (I am not sure which is the root cause though). Other processors (such as moshi) run. I ve tried the following steps: • I ve deleted the
build
folder and run manually the
kspDebugKotlin
task. Moshi's output was generated but I had no output for my processor. If I change something in the class that needs to be processed and run again the task then everything will work. If I revert the change then my processor will not work again. • clean build has the same results. Do you have any idea what's the problem? Is there any known issue?
g
Are you properly defining
Dependencies
when using
createNewFile
? (ex) Note that you can try with
--rerun-tasks
in your gradle command to ensure it doesn't skip the task due to some caching (it may help to know if the issue is more related to gradle or ksp).
v
Thank you for your answer. I use kotlinPoet to generate files and I think that it is ok with the dependencies because If I change the file then the processor will run. On revert it should run too, but it does not... It seems like something is cached... I ll try what you proposed but, there is no way to reproduce it now, so i ll have to wait
g
"no way to reproduce it now" -> You cannot change this code just to test? "kotlinPoet" -> this lib is only providing you a String that you have to write in a file via KSP caching mechanism (via
Dependencies
).
v
No! It does not have to do with any code change... After changing branches, build variants, and other actions it seems that the processor stops to work. It seems like something is cached... KotlinPoet does not return a string. It is a builder that hides implementation details, so I suppose internally they use
Dependencies
g
Oh yes ok, I forgot about the
FileSpec.writeTo(CodeGenerator, <deps>)
, sorry. (I use kotlinpoet for code gen but not write so far, but I think it's probably not your problem.)
d
In addition to the great suggestions from glureau, you can try turning on
ksp.incremental.log=true
and looking at the output to diagnose the issue https://kotlinlang.org/docs/ksp-incremental.html#reporting-bugs Another thing that can trip people up is that the instance of the subclass of
SymbolProcessor
is reused so it’s possible to introduce errors if you make it stateful
v
Great tip! I ll definitely try it to find the root of the problem. Right now it seems that
--rerun-tasks
does the trick
I ve enabled the logs and something really strange happens. When this problem occurs if I build my project on the debug variant it generates sources for my processor for the release. If I change something in the class that needs to be processed then sources for the debug variant are generated. If I revert the change, then the sources for this class are remove alongside with the logs for the debug variant!