Koin ViewModel annotation is generating a deprecated file after Koin 4.0
Describe the bug
The generated module with their respective DSL are being generated with a deprecated code.
IRL -> We work with projects that treats warning as errors in projects
To Reproduce Steps to reproduce the behavior:
- setup a project with the latest koin, koin annotations and ksp compiler.
- Create a viewmodel with Koin Annotations @KoinViewModel
- Inject into MainActivity
- Check the Module generated
Expected behavior
The generated module would be generated with the right dsl import org.koin.core.module.dsl.viewModel instead of import org.koin.androidx.viewmodel.dsl.viewModel
Koin module and version:
koin = "4.0.0" koinKsp = "1.3.1" kspPlugin = "2.0.20-1.0.24"
koinAndroid = { group = "io.insert-koin", name = "koin-android", version.ref = "koin" } koinAndroidAnnotations = { group = "io.insert-koin", name = "koin-annotations", version.ref = "koinKsp" } koinKsp = { group = "io.insert-koin", name = "koin-ksp-compiler", version.ref = "koinKsp" }
Snippet or Sample project to help reproduce
Add a snippet or even a small sample project to hel reproduce your case.
Commit -> https://github.com/felipezad/SpotlessApplication/commit/5dff6f5cedc86e15c6a5c5f2f00b201e8bc99744
Agree, I have the same issue
Same issue here
Same issue
Kotlin Jetpack Compose
using migration guide didn't fix the problem https://insert-koin.io/docs/setup/migrate
ksp = "2.0.20-1.0.24" koin-bom = "4.0.0" koin-ksp-annotations = "1.4.0-RC4"
koin-bom = { module = "io.insert-koin:koin-bom", version.ref = "koin-bom" } or koin-android = { group = "io.insert-koin", name = "koin-android", version.ref = "koin-bom" } gives same deprecated warning
koin-core-viewmodel = { group = "io.insert-koin", name = "koin-core-viewmodel", version.ref = "koin-bom" } koin-core-viewmodel-navigation = { group = "io.insert-koin", name = "koin-core-viewmodel-navigation", version.ref = "koin-bom" }
koin-annotations = { group = "io.insert-koin", name = "koin-annotations", version.ref = "koin-ksp-annotations" } koin-ksp = { group = "io.insert-koin", name = "koin-ksp-compiler", version.ref = "koin-ksp-annotations" }
Temporal Fix
package org.koin.androidx.viewmodel.dsl
import androidx.lifecycle.ViewModel
import org.koin.core.definition.Definition
import org.koin.core.definition.KoinDefinition
import org.koin.core.module.Module
import org.koin.core.module.dsl.viewModel as fixedViewModel
import org.koin.core.qualifier.Qualifier
inline fun <reified T : ViewModel> Module.viewModel(qualifier: Qualifier? = null, noinline definition: Definition<T>): KoinDefinition<T> =
fixedViewModel(qualifier = qualifier, definition = definition)
can you raise the issue in https://github.com/InsertKoinIO/koin-annotations ?
any trial on Koin Annotations 2.0-Beta1 ? This release contains the fix for that.
It works, but only if I add ksp { arg("KOIN_USE_COMPOSE_VIEWMODEL", "true") } to each module's build.gradle.kts I have ViewModels in. I was unable to configure it as a general option using buildSrc.
Side note: It's not a KMM project, just an Android multi-module project structure.
So maybe there's still some room for improvement, I guess.
Noted. Will report in on Koin Annotations project.
I close it. Let's follow on koin annotations repo.
didn't see a clear instruction outlined in here (and the IDE warning didn't indicate properly) but in case someone else is migrating and the instructions don't reveal themselves until you arrive here
remove imports
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.androidx.viewmodel.dsl.viewModelOf
add imports
import org.koin.core.module.dsl.viewModel
import org.koin.core.module.dsl.viewModelOf