Hi everyone! I have a multi-module/libraries Andro...
# ksp
m
Hi everyone! I have a multi-module/libraries Android Kotlin project and would like to check the uniqueness of ID's across module/libraries boundaries. The ID's have the following code structure:
@ErrorID val errorID = 0xA03L
Is it possible to implement such a requirement with ksp or would it require building a Kotlin compiler plugin?
j
KSP does not support evaluating expression like such. However if you can put the value of errorID in the arguments of your annotation, then it is readable in KSP
f
I think it should be possible for ksp to read
@ErrorID
and generate a new class file with a list of all those ids, which could in turn be run as a test. Not sure about how to cross modules though. I think I saw some new expensive method in one of the latest releases.
👍 1
y
yea you cannot do it w/o the help of a gradle task because annotation processor won't detect annotations in your dependencies (you would need a way to find the annotated classes). DataBinding does this via gradle tasks. You can use KSP to generate s resource file and then use a gradle plugin to check the uniqueness between modules
👍 1
not sure if it is worth it though, just an option
ASM pipeline might even be better if you can limit it to release builds (w/o any ksp task)
f
ASM?
t
If the packages containing the `errorID`s are a known set, the new
getDeclarationsFromPackage(packageName: String)
might be useful. By traversing the elements in the libraries / modules to find `errorID`s, the single test mentioned by @Fabio can be generated. Depending on where
errorID
can appear (e.g., only top level), it might not be that expensive. Those `errorID`s has to be visible to the test, though.