Using KTOR client plugins for plugin development

ktor comes bundled if you use the intellijPlatform gradle plugin dependencies. I can develop, test, run ide when using client plugins like ContentNegotiation and CIO engine. e.g (import io.ktor.client.plugins.contentnegotiation.*
) and looking at the gradle external libraries i can see it under idea:ideaIC:2023.3.8.

The problem is when i run the buildPlugin gradle task from the intellij gradle plugin and try to use load the plugin from the zip file I get errors like java.lang.NoClassDefFoundError: io/ktor/client/engine/cio/CIO and same for other client plugins like ContentNegotiation.

KTOR should be bundled with the ide but are the client plugins not bundled? I Tried to add implementation(“io.ktor:ktor-client-content-negotiation:$ktorVersion”) in my build.gradle file but i dont know the ktorVersion so i guessed a random version but then i get an error

com.intellij.platform.instanceContainer.instantiation.InstantiationException: Class ‘class com.github.somtooo.gitnotify.services.ConfigurationCheckerService’ does not define any of supported signatures ‘[(Project)void, (Project,CoroutineScope)void, (CoroutineScope)void, ()void]’
but im sure the ConfigurationCheckerService uses the correct constructor for service classes. Cause it works if i remove implementation(“io.ktor:ktor-client-content-negotiation:$ktorVersion”). Thanks

If the code compiles, but fails at runtime, then you’re probably missing the necessary runtime dependency declarations. Later versions of the IDE are more strict in what classes or libraries they provide to plugins at runtime.

For ktor, there’s the module intellij.libraries.ktor.client.
With a v1 (i.e. the usual) plugin descriptor, you probably need <depends>intellij.libraries.ktor.client</depends> in your plugin.xml. I’ve only used this with a v2 descriptor, though. As far as I can tell, there’s also a intellij.libraries.ktor.client.cio, but I’ve not used it so far.

In general, all the bundled libraries and versions are listed here: Third Party Software and Licenses - JetBrains.

Thanks for replying but i cant add <depends>intellij.libraries.ktor.client</depends> to my plugin.xml says Cannot resolve plugin 'intellij.libraries.ktor.client' in dependencies (Reference: Plugin Dependencies).

Nevertheless was able to make it work by adding the client libraries as dependencies in my build.gradle.kts and then excluding the coroutines module from them. This solved the ConfigurationCheckerService’ does not define any of supported signatures ‘[(Project)void, (Project,CoroutineScope)void, (CoroutineScope)void, ()void]’

implementation("io.ktor:ktor-client-cio:${ktorVersion}") { exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-core") } implementation("io.ktor:ktor-client-content-negotiation:${ktorVersion}") { exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-core") } implementation("io.ktor:ktor-serialization-kotlinx-json:${ktorVersion}") { exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-core") }

And you were right about later ide versions are more strict in what classes or libraries they provide to plugins at runtime. Upgrading my platformVersion to 2024.3.5 removed all the client libraries so couldn’t compile.

Thanks again for the response

I had a quick look at your plugin sources.

If you add this right above instrumentationTools() in your build.gradle.kts:

        bundledModule("intellij.libraries.ktor.client")
        bundledModule("intellij.libraries.ktor.client.cio")

        // instrumentationTools()

and this in your plugin.xml:

    <depends>intellij.libraries.ktor.client</depends>
    <depends>intellij.libraries.ktor.client.cio</depends>

then you can compile even when you remove your own dependencies to KTOR.

It’s usually strongly recommended to not bundle libraries, which are bundled with the IDE, in a plugin. It’s possible to get weird classloader errors, for example.

Thanks using bundledModule("intellij.libraries.ktor. bundledModule("intellij.libraries.ktor.client.cio")
I could compile but still dosen’t work at runtime.
Adding:
<depends>intellij.libraries.ktor.client</depends> inspection shows:
Cannot resolve plugin 'intellij.libraries.ktor.client' in dependencies (Reference: Plugin Dependencies) and when you run the runIde task it says:
Plugin 'git-notify' requires plugin 'intellij.libraries.ktor.client' to be installed

Very strange since the bundledModule() is working dont know why cant see it

Created a branch with the changes. - GitHub - somtooo/git-notify at bugfix/ktor-build

Hm, then I don’t know how to fix it. Removing the dependency doesn’t help either.

It would be possible with a v2 plugin descriptor, e.g. like Python. But you’d have to change your plugin metadata for this. I’m not sure if JetBrains is recommending v2 at this time or not…

A JetBrains developer would have to comment here if it’s possible to use the ktor modules with a v1 descriptor, I think.