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
Jiaxiang
04/13/2021, 9:22 AM
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
Fabio
04/13/2021, 10:29 AM
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
yigit
04/13/2021, 3:59 PM
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
yigit
04/13/2021, 3:59 PM
not sure if it is worth it though, just an option
yigit
04/13/2021, 4:00 PM
ASM pipeline might even be better if you can limit it to release builds (w/o any ksp task)
f
Fabio
04/14/2021, 4:48 AM
ASM?
t
Ting-Yuan Huang
04/14/2021, 5:31 AM
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.