google / ksp

Kotlin Symbol Processing API

Home Page:https://github.com/google/ksp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add module information to `SymbolProcessorEnvironment`

dewantawsif opened this issue · comments

On improving a library I maintain FlexibleHilt I've decided to aggregate classes per package like below:

Now the issue is if users for whatever reason decides to have the same package in different modules it'll make duplicate interface with same name across module causing issues while building the app. Given we have access to module name we can append it to the class name to ensure it stays unique.


Previous issue on this are #1015, #1097 and the general answer was to pass the module name via KSP options in the gradle script.

While that is possible it adds a extra work on the end user and also another thing to keep an eye on when they rename/switch the module. As such I think it'll be better to let us handle them in the ksp processors directly.

I would also like to note that it'll be nice if the module information had data on sub-modules too so we can get the whole path like :core:analytics

While that is possible it adds a extra work on the end user and also another thing to keep an eye on when they rename/switch the module

What about using project.path or getProject().getPath() when configuring it, then you don't need to worry about renames. I'm not opposed to having the information easily available in KSP, but considering it's pretty trivial to make a convention plugin that can automatically do the above, it seems that adding it directly to KSP doesn't make a lot of sense as then it simply becomes a matter of applying the convention plugin (which can also apply the KSP plugin at the same time, therefore not really adding any additional work).

Fair point. But they did add module name recently to resolver so might as well include the project path