kotlin-inject icon indicating copy to clipboard operation
kotlin-inject copied to clipboard

KSP throws an exception when using an interface from another module to declare a property in a component

Open KYamshanov opened this issue 2 years ago • 4 comments

Hi! I want to use kotlin-inject in my multi modules multi platform project. But when I use interface from another module for declare a property in my component I get an exception:

e: Error occurred in KSP, check log for detail [ksp] Unresolved reference: MyInterface

and

[ksp] Unable to process:me.tatarka.inject.compiler.ksp.InjectProcessor: ModuleComponent

source code of component

KYamshanov avatar Jun 27 '23 09:06 KYamshanov

Same here for third-party interfaces/classes. I can't get a @Provides annotation to work for this case. I'm using a workaround with delegates, but this is currently a show stopper for me.

(I can use types of other modules in my project though)

kalinjul avatar Sep 11 '23 15:09 kalinjul

Ok so the solution for me was to include the dependencies in the module that has the component. My Situation: Android App, several modules, @Provides declared in one interface per module that are implemented by an AppComponent in the app module (similar to tivi app https://github.com/chrisbanes/tivi/blob/76c9ffea05ba86810a344e6ca5f936db2c67fce7/shared/prod/src/androidMain/kotlin/app/tivi/inject/AndroidApplicationComponent.kt#L25)

The app module (with the kotlin-inject component in it) needs access to all declared @Provides return types. So i need to either change third-party dependencies to "api" or add them to the app's implementation configuration. This is not the case with dagger, so it confused me.

kalinjul avatar Sep 12 '23 07:09 kalinjul

Ah yes, the codegen has less indirection than dagger which causes this as a side-effect. Can look into seeing if there's more cases where you could 'hide' the types provided though there are trade-offs there.

evant avatar Sep 12 '23 18:09 evant

Is there an update on this? I would really like to use kotlin-inject, but I'm having trouble in my multi-module project as well for the same reason.

19lmyers avatar May 23 '24 20:05 19lmyers