Hello everyone, I have currently a use case to fin...
# compiler
r
Hello everyone, I have currently a use case to find all descriptors in the classpath annotated with a custom annotation. To implement this search I’m currently using a function that recursively walks all class path packages https://github.com/arrow-kt/arrow-meta/blob/883d4810ec37c57435d1a6a367368fb240030b[…]analysis/phases/analysis/solver/collect/ConstraintCollection.kt Here, I’m scanning each package and its subpackages recursively looking for the annotation on one of the child descriptors. This is extremely slow and incurs in a considerable startup time for plugins when the classpath is too big. Is there a way to retrieve a list of annotated descriptors from the classpath without recursively walking all packages like this? thank you!
f
The reflections library can do this fast.
👀 1
c
i think classgraph is the fastest.
👍 1
but classpath scanning is never fast
f
Or maybe the new JetBrains plugin is usable for you: https://kotlinlang.slack.com/archives/C7L3JB43G/p1631889133070500
e
+1 for classgraph, although I'm not sure it can be useful for your specific conditions
r
In regards to compiler plugins what I did is generating a hint in a specific package each time someone is using the annotation. Then the scanner only has to read the generated hints instead of scanning the entire classpath. Maybe that’s an option.
s
+1 for hint, generating a dummy class/file linking to symbols worked for me
r
thanks everyone for all the suggestion, we’ll check them out! 🙏
a
thanks for all your help! @ralf do you happen to have an example of how to encode those hints in a good way?
a
awesome! 🙏
a
Yes, if all information is known at the compile time you can use the Reflekt plugin, we will release a version that supports incremental compilation in a couple of weeks (hope no more than after two). Our approach uses descriptors and scans the classpath at the compile time