koin-annotations icon indicating copy to clipboard operation
koin-annotations copied to clipboard

@ComponentScan behavior with no value provided has changed since 2.0.0-RC3 and can break compilation

Open krzdabrowski opened this issue 8 months ago • 0 comments
trafficstars

Describe the bug Created from this comment.

Koin started to generate defaultModules in my project, in multi-module projects it'd be normal to generate multiple default modules, which is causing naming conflicts and failing to compile.

It was working back in RC1, and does not work in RC3 and RC4.

Declaring exact package value for @ComponentScan solves this issue.

To Reproduce Quoting from my linked comment.

Here are some traits that I believe might be helpful to reproduce it:

  • Kotlin Multiplatform project, with commonMain, androidMain and iosMain sets
  • also, Gradle multi-module project
  • module names can look 'similar' to Koin when generating code, for example I had issue with modules :feature:login:data and :feature:settings:data

With no specific parameter value used in @ComponentScan, it looked like it couldn't "make a hit" with my scanned dependencies into the module I'd expect, resulting in hitting into defaultModule. This happened at least for few of my dependencies, landing into its defaultModules in each Gradle module. But somehow, for Koin, in the setup of multi-module KMP project, the paths were conflicting somehow, seeing "redeclaration of defaultModule error" while compilation. That's all what I have.

EDIT: I think I might have found the scenario. Have a module like this - both scanning for components, and declaring some on its own:

@Module
@ComponentScan
object SettingsModule {

    @Factory
    (...)
}

Then, create a sub-package and have another dependency there you want to scan, like:

@Single
internal class SettingsRepositoryImpl (...)

This dependency will not be added to generated module, but rather lands in defaultModule. When such situation happens for multiple Gradle and Koin modules, it creates multiple defaultModules, hence redeclaration and failing the compilation.

EDIT2: It also happened to me with the Koin module without any declarations inside, and other annotated dependency located in the same package - however, I don't know why it happened for that one module. But the result is the same - creating defaultModule, which causes issues.

EDIT3: All my problematic modules are located in commonMain so I believe the project needs to be a KMP one.

Declaring the package name in @ComponentScan parameter value fixes the issue but it feels like a regression because it worked in RC1.

Expected behavior The behavior for @ComponentScan without any value should remain the same as RC1.

Koin project used and used version (please complete the following information): Koin 4.0.2, Koin Annotations 2.0.0-RC4

krzdabrowski avatar Feb 24 '25 17:02 krzdabrowski