koin icon indicating copy to clipboard operation
koin copied to clipboard

[Koin annotations]

Open azartx opened this issue 9 months ago • 2 comments

Title: KSP Validation False Positive for Cross-Module Interface Bindings in KMP Project


Environment

  • Koin Version: 4.0.2
  • Koin Annotations: 2.0.0
  • Koin KSP Compiler: 2.0.0
  • KSP Version: 2.1.10-1.0.30
  • Kotlin Version: 2.1.10
  • Gradle Version: 8.12
  • Platform: Android/iOS (KMP)

Problem Description

When using Koin with KSP in a KMP multi-module project, the KSP validation incorrectly reports a missing dependency during compilation (Missing Definition for property 'AuthRepository'), even though:

  1. All bindings are correctly annotated with @Single(binds = [...].
  2. Modules are properly included in the root Koin module.
  3. Dependencies between modules are correctly configured.

The project works at runtime when validation is disabled via KOIN_CONFIG_CHECK = false, proving the bindings are valid.


Steps to Reproduce

  1. Project Structure:

    • domain module: Declares interfaces (AuthRepository, AuthInteractor).
    • data module: Implements AuthRepositoryImpl with @Single(binds = [AuthRepository::class]).
    • di module: Aggregates all modules via @Module(includes = [...]).
  2. Configuration:

    • All modules have KSP plugin and dependencies:
      ksp("io.insert-koin:koin-ksp-compiler:2.0.0")  
      
    • data module depends on domain.
    • Root di module includes all submodules.
  3. Error:

    • Compilation fails with:
      [ksp] --> Missing Definition for property 'authRepository : com.example.domain.AuthRepository'  
      in 'com.example.domain.AuthInteractorImpl'  
      

Expected Behavior

KSP should recognize cross-module interface bindings and not report false validation errors when:

  • Implementations are annotated correctly.
  • Modules are properly included.
  • Dependencies are configured between modules.

Actual Behavior

KSP validation incorrectly claims a missing binding for an interface implemented in another module.
Workaround: Disabling validation via KOIN_CONFIG_CHECK = false for just domain module or whole project allows successful compilation and runtime execution.


Additional Context

  1. Verifications:

    • Interfaces are declared in domain.
    • Implementations in data use @Single(binds = [...].
    • Root Koin module includes all submodules.
    • KSP is configured in all modules.
  2. Logs: [ksp] [ERROR] Missing Definition for property 'authRepository : com.example.domain.AuthRepository' in 'com.example.domain.AuthInteractorImpl'.


Possible Causes

  1. KSP validation does not resolve cross-module dependencies correctly for Koin annotations.
  2. Koin KSP processor misses interface bindings declared in a separate module.

azartx avatar Mar 30 '25 00:03 azartx

I'm facing the exact same issue in Koin 4.0.4 and Koin annotations 2.0.0

marcelpallares avatar Apr 15 '25 10:04 marcelpallares

can you open issue in https://github.com/InsertKoinIO/koin-annotations/issues

arnaudgiuliani avatar Jun 06 '25 14:06 arnaudgiuliani

Please check with 2.2 or 2.3 annotations

arnaudgiuliani avatar Oct 22 '25 07:10 arnaudgiuliani