InsertKoinIO / koin-annotations

Koin Annotations - About Koin - a pragmatic lightweight dependency injection framework for Kotlin & Kotlin Multiplatform insert-koin.io
https://insert-koin.io
Apache License 2.0
163 stars 44 forks source link

KoinDefAndroidxLifecycleViewModel class generated in multiple modules #178

Closed alexandrucaraus closed 1 month ago

alexandrucaraus commented 1 month ago

Using koin annotations and view model in CMP multimodule project. The issue is when I have two feature packages, packageA and packageB, and both use generated compose view models.

The problem is in generated KoinMeta class of each module. Each dependency in generated meta class has the format,

KoinMeta-packageA package org.koin.ksp.generated public class KoinDef{PackageA}Deep public class KoinDef{pacakgeA}Deep public class KoinDefAndroidxLifecycleViewModel

KoinMeta-packageB package org.koin.ksp.generated public class KoinDef{packageB}Dep1 public class KoinDef{pacakgeB}Dep3 public class KoinDefAndroidxLifecycleViewModel

When building the app, the builder complains about the KoinDefAndroidxLifecycleViewModel, says it's duplicate, and indeed it is.

Can it be generated so it has KoinDef{package}AndroidxLifecycleViewModel format?

When I use the viewmodels as kotlin DSL it works. When I use the packages without viewmodels in similar manner it works.

Versions: koin = "4.0.0" koin-ksp = "1.4.0-RC4"

arnaudgiuliani commented 1 month ago

I couldn't reproduce it in app with Koin 3.5.6 / KA 1.4.0-RC4. Do you have any way to reproduce?

I've seen generation of one KoinDefAndroidxLifecycleViewModel, not twice.

alexandrucaraus commented 1 month ago

Created a repro

https://github.com/alexandrucaraus/koinannotationsrepro178.git

arnaudgiuliani commented 1 month ago

Fixed in 1.4.0 👌

arnaudgiuliani commented 1 month ago

tested on Koin Annotations 2.0-Beta1. Don't forget to use @ComponentScan on your module classes.