ansman/kotshi

Best practices in multi-modular projects

Opened this issue · 1 comments

Hi. I just have a question about a Kotlin best practices in multi-modular projects.

In the current setup I have multiple sub-modules with its own models annotated with @JsonSerializable and Factories. So each of them have the factory generated in the build directory, Then in the top module which is a lambda function module in my case I create moshi instance and I add all factories from submodules to it.

Is this a right approach?
Will it be possible for Kotshi to automatically gather those factories and create one wrapper factory?

Unfortunately Kotshi doesn't have support for generating aggregate factories across modules. This mostly stems from a limitation in KSP/KAPT as it can only find annotated classes in a single module. There are ways around this that Hilt uses for example but they aren't ideal here.

I've been considering adding support for Moshi's codegen which would let you skip adding a factory all together but it does require reflection and some proguard rules to be generated.

For now your options are either to create one factory per module like you do now or to switch to Moshi's official codegen.