When @Single or @Factory is placed on a top-level function, the compiler
plugin silently ignores it. No definition is generated, and the app crashes
at runtime with NoDefinitionFoundException.
No compile-time warning or error is produced.
To Reproduce
@Single
fun json(): Json = Json {
isLenient = true
ignoreUnknownKeys = true
}
At runtime:
No definition found for type 'kotlinx.serialization.json.Json' on scope '['root']'
Workaround
Wrapping the return value in a provider class works:
@Single
class JsonProvider {
fun get(): Json = Json {
isLenient = true
ignoreUnknownKeys = true
}
}
Environment
- koin: 4.2.2
- koin-annotations: 4.2.2
- koin-compiler-plugin: 1.0.1
- kotlin: 2.4.0
When
@Singleor@Factoryis placed on a top-level function, the compilerplugin silently ignores it. No definition is generated, and the app crashes
at runtime with
NoDefinitionFoundException.No compile-time warning or error is produced.
To Reproduce
At runtime:
No definition found for type 'kotlinx.serialization.json.Json' on scope '['root']'
Workaround
Wrapping the return value in a provider class works:
Environment