enableTopLevelFunctionInjection

@DelicateMetroGradleApi(message = "Top-level function injection is experimental and does not work yet in all cases. See the kdoc.")
val enableTopLevelFunctionInjection: Property<Boolean>(source)

Enables injection for top-level functions. See the kdoc on Inject for more details.

This is disabled by default because it makes incremental builds recompile more files. See https://zacsweers.github.io/metro/latest/performance/#incremental-compilation.

Warnings

  • Prior to Kotlin 2.3.20-Beta1, top-level function injection is only compatible with jvm/android targets.

  • Prior to Kotlin 2.3.20-Beta1, top-level function injection is not yet compatible with incremental compilation on any platform

  • Kotlin/JS supports this with incremental compilation enabled starting in Kotlin 2.3.21 and Kotlin 2.4.0-Beta2. See https://youtrack.jetbrains.com/issue/KT-82395