Home > OS >  how can i fix the installation of Koin in ktor/intellij
how can i fix the installation of Koin in ktor/intellij

Time:02-28

I'm trying to use install koin but it gives the following text when i hover over it.

Type mismatch. Required: Plugin<TypeVariable(P), TypeVariable(B), TypeVariable(F)> Found: Koin.Feature

the code is as in the following:

import io.ktor.server.application.*
import org.koin.ktor.ext.Koin

fun Application.configureKoin(){
install(Koin){
    
}
}

CodePudding user response:

Seems like you are trying to install a plugin, that's written for Ktor 1.*, in a Ktor server with version 2.*. To make it work you have to use Ktor server 1.*, e.g 1.6.7, or wait until plugin maintainers migrate to version 2.0.0. Here you can find a list of incompatible changes and a migration guide for Ktor 2.0.0.

CodePudding user response:

Had the same issue. Which version of the ktor plugin are you using? I was using 2.0.0 beta and changed to 1.6.4 and it works now. Can find it in the gradle.properties file.

CodePudding user response:

Until the Ktor 2.0 plugin for Koin is added, you can use the solution below, which is taken from here (credits to phucynwa). Also, you can track the Pull request here.

object KoinPlugin : ApplicationPlugin<Application, KoinApplication, Unit> {

   override val key: AttributeKey<Unit>
       get() = AttributeKey("Koin")

   override fun install(
       pipeline: Application,
       configure: KoinApplication.() -> Unit
   ) {
       val monitor = pipeline.environment.monitor
       val koinApplication = startKoin(appDeclaration = configure)
       monitor.raise(EventDefinition(), koinApplication)

       monitor.subscribe(ApplicationStopping) {
           monitor.raise(EventDefinition(), koinApplication)
           stopKoin()
           monitor.raise(EventDefinition(), koinApplication)
       }
   }
}

fun Application.installPlugins() {
   install(KoinPlugin)
}
  • Related