evant / kotlin-inject

Dependency injection lib for kotlin
Apache License 2.0
1.29k stars 58 forks source link

Generated code is not accessible from commonMain #340

Closed edenman closed 9 months ago

edenman commented 9 months ago
kotlin = "1.9.21"
ksp = "1.9.21-1.0.15"
kotlinInject = "0.6.3"

I'm using generateCompanionExtensions. My components are defined in composeApp/src/commonMain/kotlin/Foo.kt and i can see the generated code and it looks correct, but I'm not able to import the create method (if I try to add this dep it creates a circular dep). Feels like something very easy but I can't figure it out. Repro project: https://github.com/edenman/atlas-client

Screenshot 2024-01-28 at 15 47 22
evant commented 9 months ago

We have a multiplatform sample here, am also going to look into the new processing scheme in ksp2 which should make this simpler

edenman commented 9 months ago

Yeah, I'm assuming it's something to do with me using the Compose Multiplatform sample app as a base. It has a different structure than your sample. In particular, the generated InjectAppComponent ends up here: composeApp/build/generated/ksp/android/androidDebug/kotlin/di/InjectAppComponent.kt. Sort of makes sense that it wouldn't be accessible from composeApp/src/commonMain/....maybe I'm just using it wrong? Is the idea that you only ever access the generated code from the iOS/Android/whatever code?

evant commented 9 months ago

Yeah the way that ksp currently works is it generates per-platform. ksp2 has an experimental option to generate per sourceset instead.

edenman commented 9 months ago

Thanks, makes sense. I was assuming I'd want to create the graph in the common code. You can probably close this? Up to you.

evant commented 9 months ago

Yeah, opened https://github.com/evant/kotlin-inject-samples/issues/17 for the investigation