@PropertyValue from one module not visible to @Property in another module — MissingPropertyException

Open
#28 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
kotlin

Research direction

Start with the compiler-plugin processing for @PropertyValue and @Property across the separate Module A and Module B compilation units; the runtime failure is reported at org.koin.core.scope.Scope.getProperty (Scope.kt:430). Reproduce the shown startKoin setup and confirm completion when the cross-module value resolves without MissingPropertyException, while preserving the documented properties() workaround.

Written by the indexing model from the issue text.

Description

type:feature-request 🫶

Environment

  • Koin BOM: 4.2.1
  • Koin Annotations Compiler Plugin: 1.0.0-RC1
  • Project type: Kotlin Multiplatform (shared module) + Android (app module)

Description

@PropertyValue declared in one module is not resolved by @Property in another module, causing MissingPropertyException at runtime.

Minimal reproducible example

Module A (shared, KMP commonMain):

class Greeting(val message: String)

@Module
@ComponentScan
@Configuration
class ModuleA {
    @Single
    fun greeting(
        @Property("host") host: String,
    ): Greeting = Greeting("Hello from $host")
}

Module B (app, Android):

@Module(includes = [ModuleA::class])
@ComponentScan
@Configuration
class ModuleB

@PropertyValue("host")
val host = "https://example.com"

Initialization:

fun main() {
    startKoin {
        modules(ModuleB::class)
    }
    val greeting = getKoin().get<Greeting>()
    println(greeting.message) // crashes
}

Crash

MissingPropertyException: Property 'host' not found
    at org.koin.core.scope.Scope.getProperty(Scope.kt:430)

Expected behavior

@PropertyValue("host") in Module B registers the value globally, making it available to @Property("host") in Module A.

Actual behavior

The property is not found at resolution time. It appears that @PropertyValue annotations are only processed within the compilation unit where they are declared. Since Module A and Module B are separate Gradle modules (separate KSP/compiler plugin runs), the generated code for Module A has no knowledge of the property values declared in Module B.

Also tried

Annotating the parameter with @Provided in Module A to signal it will be supplied externally:

@Single
fun greeting(
    @Provided @Property("host") host: String,
): Greeting = Greeting("Hello from $host")

This did not resolve the issue — same MissingPropertyException.

Workaround

Pass properties explicitly via properties() in startKoin:

startKoin {
    properties(mapOf("host" to "https://example.com"))
    modules(ModuleB::class)
}

Notes

  • @PropertyValue works correctly when declared in the same module/compilation unit as the @Property consumer.
  • The issue is specific to cross-module usage where each module is a separate Gradle module with its own KSP processing.
Dominant language
Kotlin
Stars
82
Forks
15
Avg merge
1m
Merged PRs (30d)
1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from InsertKoinIO/koin-compiler-plugin

All issues in InsertKoinIO/koin-compiler-plugin

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.