You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> Code generation can be configured for both the common source set and all target source sets, but that will likely lead to [Redeclaration errors for @Component when ksp is used for common and target source sets](https://github.com/evant/kotlin-inject/issues/194).
79
80
80
81
If a `Component` is declared in the common source set, then KSP would typically be configured to generate code in the common source set. This means that the generated code will be accessible from the common source set, and any source set that depends on it.
@@ -83,7 +84,7 @@ However, certain scenarios instead require generating code for all target source
83
84
84
85
In those cases, while the `Component` might be declared in the common source set, it is not possible to create it, because the `create` functions are declared in each target source set.
85
86
86
-
> [!NOTE]
87
+
> [!NOTE]
87
88
> Pre Kotlin 2.0 it is possible to reference the `create` function from the common source set because code from a target source set was visible to the common source set.
88
89
> However this can lead to very subtle bugs, and starting from Kotlin 2.0 common source sets can no longer see code from target source sets.
89
90
@@ -102,15 +103,15 @@ actual fun createKmp(): MyKmpComponent = MyKmpComponent::class.create()
102
103
103
104
Creating an `actual fun` for each platform can be tedious, so kotlin-inject provides a `KmpComponentCreate` annotation.
104
105
105
-
```kotlin
106
+
```kotlin
106
107
@Component
107
108
abstractclassMyKmpComponent
108
109
109
110
@KmpComponentCreate
110
111
expectfuncreateKmp(): MyKmpComponent
111
112
```
112
113
113
-
> [!NOTE]
114
+
> [!NOTE]
114
115
> Make sure you are using the `kotlin-inject-runtime-kmp` artifact in order to have access to the `KmpComponentCreate` annotation.
115
116
116
117
kotlin-inject's processor will generate an `actual fun` in each target's source set that calls through to the `create` function for `MyKmpComponent`. The generated code looks like this:
@@ -171,19 +172,16 @@ The only difference is for projects that generate code into each KMP target sour
171
172
kotlin {
172
173
// add your project's targets here like in the snippet above
0 commit comments