Description
After upgrading from 0.6.2 to 1.0.0-RC2, compileSafety causes a false positive "Missing definition" error when compiling test source sets (compileDebugUnitTestKotlin). The main source set compiles successfully — the error only appears during test compilation.
The generated hint file for the main source set correctly includes the binding (verified via javap), but the compiler plugin's deferred validation in the test compilation cannot resolve it.
Environment
- Koin BOM:
4.2.1
- Koin Compiler Plugin:
1.0.0-RC2
- Kotlin:
2.3.20
- Project type: Kotlin Multiplatform (Android + iOS), multi-module
Reproduction
Module structure
:shared → SharedModule @ComponentScan("com.example.shared")
:feature → FeatureModule @ComponentScan("com.example.feature"), includes SharedModule
:app → AppModule @ComponentScan("com.example"), includes FeatureModule
Shared module — interface
// :shared — com.example.shared.bridge.UserRepository
interface UserRepository {
fun getUserId(): String
}
Feature module — ViewModel consuming the interface
// :feature — com.example.feature.ui.HomeViewModel
@KoinViewModel
class HomeViewModel(
@Provided
private val userRepository: UserRepository,
) : ViewModel() { ... }
App module — implementation
// :app — com.example.app.data.UserRepositoryImpl
@Single
class UserRepositoryImpl(
private val context: Context,
) : UserRepository {
override fun getUserId(): String = "..."
}
App module — root module
// :app
@Module(includes = [FeatureModule::class])
@ComponentScan("com.example")
class AppModule { ... }
Koin initialization
startKoin {
androidContext(application)
module<AppModule>()
}
Test (any test in :app)
// :app/src/test/...
class SomeTest {
@Test
fun example() {
// Doesn't even need to reference UserRepository
assertEquals(1, 1)
}
}
Error
> Task :app:compileDebugUnitTestKotlin FAILED
e: [Koin] Missing definition: com.example.shared.bridge.UserRepository
Required by a call site in a dependency module (deferred validation).
No matching definition found in any declared module.
Check your declaration with Annotation or DSL.
Key observations
-
Main compilation succeeds — the generated hint file correctly registers the binding:
componentscan_..._AppModule_single(UserRepositoryImpl, UserRepository)
-
Test compilation fails — the deferred validation from the dependency module :feature cannot be resolved during the test source set compilation, even though the main source set already resolved it.
-
@Provided is correctly set on the ViewModel parameter in the :feature module.
-
Workaround: Setting koinCompiler { compileSafety = false } in the :app module resolves the issue, but disables all compile-time validation for that module.
Expected behavior
The compiler plugin should either:
- Not run deferred validation during test source set compilation, or
- Resolve deferred bindings against the main source set's generated hints during test compilation
Related issues
Description
After upgrading from
0.6.2to1.0.0-RC2,compileSafetycauses a false positive "Missing definition" error when compiling test source sets (compileDebugUnitTestKotlin). The main source set compiles successfully — the error only appears during test compilation.The generated hint file for the main source set correctly includes the binding (verified via
javap), but the compiler plugin's deferred validation in the test compilation cannot resolve it.Environment
4.2.11.0.0-RC22.3.20Reproduction
Module structure
Shared module — interface
Feature module — ViewModel consuming the interface
App module — implementation
App module — root module
Koin initialization
startKoin { androidContext(application) module<AppModule>() }Test (any test in :app)
Error
Key observations
Main compilation succeeds — the generated hint file correctly registers the binding:
Test compilation fails — the deferred validation from the dependency module
:featurecannot be resolved during the test source set compilation, even though the main source set already resolved it.@Providedis correctly set on the ViewModel parameter in the:featuremodule.Workaround: Setting
koinCompiler { compileSafety = false }in the:appmodule resolves the issue, but disables all compile-time validation for that module.Expected behavior
The compiler plugin should either:
Related issues