IntelliJ plugin registering custom .kts script type not able to execute it

I’ve tried creating an intellij plugin to add a custom kotlin script support via the SciptDefinitionsProvider endpoint. I managed (after some extended period of time) to get it working, that ide recognizes the plugin, associates my kts script extension with it and even the intellisense works great, when I write a script with this extension, it shows no errors, shows context-aware hints, like showing packages of the custom classes I use, showing method parameter names and I can even use the decompiler to inspect their code. Unfortunately, when I try to run the script, I get this error. I have no idea how to debug it. I tried making changes in the dependency list and classpath and nothing helped. Can anyone please help suggesting what may be the cause or how to solve it?

I add the scripting libraries like this

compileOnly("org.jetbrains.kotlin:kotlin-scripting-common")
compileOnly("org.jetbrains.kotlin:kotlin-scripting-jvm")
compileOnly("org.jetbrains.kotlin:kotlin-scripting-intellij")
exception: java.lang.NoSuchMethodError: 'java.lang.Object org.jetbrains.kotlin.config.CommonConfigurationKeysKt.getScriptingHostConfiguration(org.jetbrains.kotlin.config.CompilerConfiguration)'
	at org.jetbrains.kotlin.scripting.compiler.plugin.ScriptingK2CompilerPluginRegistrar$Companion.registerComponents(pluginRegisrar.kt:98)
	at org.jetbrains.kotlin.scripting.compiler.plugin.ScriptingK2CompilerPluginRegistrar.registerExtensions(pluginRegisrar.kt:108)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.registerExtensionsFromPlugins$cli_base(KotlinCoreEnvironment.kt:807)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$ProjectEnvironment.registerExtensionsFromPlugins(KotlinCoreEnvironment.kt:197)
	at org.jetbrains.kotlin.cli.pipeline.jvm.JvmScriptPipelinePhase.executePhase$lambda$0(JvmScriptPipelineStep.kt:42)
	at kotlin.UnsafeLazyImpl.getValue(Lazy.kt:100)
	at org.jetbrains.kotlin.cli.pipeline.jvm.JvmScriptPipelinePhase.executePhase$lambda$1(JvmScriptPipelineStep.kt:36)
	at org.jetbrains.kotlin.cli.pipeline.jvm.JvmScriptPipelinePhase.executePhase(JvmScriptPipelineStep.kt:50)
	at org.jetbrains.kotlin.cli.pipeline.jvm.JvmScriptPipelinePhase.executePhase(JvmScriptPipelineStep.kt:22)
	at org.jetbrains.kotlin.cli.pipeline.PipelinePhase.phaseBody(PipelinePhase.kt:68)
	at org.jetbrains.kotlin.cli.pipeline.PipelinePhase.phaseBody(PipelinePhase.kt:58)
	at org.jetbrains.kotlin.config.phaser.NamedCompilerPhase.invoke(CompilerPhase.kt:102)
	at org.jetbrains.kotlin.backend.common.phaser.CompositePhase.invoke(PhaseBuilders.kt:22)
	at org.jetbrains.kotlin.config.phaser.CompilerPhaseKt.invokeToplevel(CompilerPhase.kt:53)
	at org.jetbrains.kotlin.cli.pipeline.AbstractCliPipeline.runPhasedPipeline(AbstractCliPipeline.kt:109)
	at org.jetbrains.kotlin.cli.pipeline.AbstractCliPipeline.execute(AbstractCliPipeline.kt:68)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecutePhased(K2JVMCompiler.kt:79)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecutePhased(K2JVMCompiler.kt:45)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:90)
	at org.jetbrains.kotlin.cli.common.CLICompiler.exec(CLICompiler.kt:352)
	at org.jetbrains.kotlin.cli.common.CLICompiler.exec(CLICompiler.kt:330)
	at org.jetbrains.kotlin.cli.common.CLICompiler.exec(CLICompiler.kt:294)
	at org.jetbrains.kotlin.cli.common.CLICompiler$Companion.doMainNoExit(CLICompiler.kt:431)
	at org.jetbrains.kotlin.cli.common.CLICompiler$Companion.doMainNoExit$default(CLICompiler.kt:426)
	at org.jetbrains.kotlin.cli.common.CLICompiler$Companion.doMain(CLICompiler.kt:418)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler$Companion.main(K2JVMCompiler.kt:252)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.main(K2JVMCompiler.kt)

If you need any other info, please don’t hesitate to ask, I just don’t even know which part of the code is relevant as I have no idea what is the cause

Dobrý den, pane docente / Hello,

Can you provide more context?

  • What is the place or situation where you add the scripting support?
  • If possible, can you share your sources? Or if not possible, at least the relevant parts?

Hello Róbert,
the place where I add the scripting support is an otherwise empty IntelliJ plugin. I use the ScriptDefinitionsProvider endpoint in org.jetbrains.kotlin and my implementation of it is the only class in the plugin.

The provider class is

class WindScriptDefinitionsProvider : ScriptDefinitionsProvider {

    override val id: String = "WindScriptDefinitionsProvider"

    override fun getDefinitionClasses(): Iterable<String> {
        return listOf("com.closedbrain.windscale.windscript.WindScript")
    }

    override fun getDefinitionsClassPath(): Iterable<File> {
        return classpathFromClassloader(WindScript::class.java.classLoader) ?: emptyList()
    }

    override fun useDiscovery(): Boolean = false
}

The script class is

@KotlinScript(
    fileExtension = "wind.kts",
    compilationConfiguration = WindScriptCompilerConfiguration::class,
    evaluationConfiguration = WindScriptEvaluationConfiguration::class
)
abstract class WindScript(
    val standalone: Boolean = true,
    val path: File? = null,
    val saveDir: File = File("data"),
    val result: WindScriptResult? = null
) {
    init {
        state = State()

        state.standalone = standalone
        state.path = path
        state.saveDir = saveDir
    }
}

The gradle dependencies for the plugin are

dependencies {
    intellijPlatform {
        intellijIdea("2025.3.4")

        bundledPlugin("org.jetbrains.kotlin")

        testFramework(org.jetbrains.intellij.platform.gradle.TestFrameworkType.Platform)
    }

    compileOnly("org.jetbrains.kotlin:kotlin-scripting-common")
    compileOnly("org.jetbrains.kotlin:kotlin-scripting-jvm")
    compileOnly("org.jetbrains.kotlin:kotlin-scripting-intellij")

    implementation(project(":WindScript")) {
        exclude(group = "org.jetbrains.kotlin")
    }
}

(The script is in a separate module from the plugin, both are direct submodules of an empty parent module)

I don’t know if that’s relevant, but here’s also my Compiler config

object WindScriptCompilerConfiguration: ScriptCompilationConfiguration({
    compilerOptions("-Xcontext-parameters")

    defaultImports("com.closedbrain.windscale.windscript.tools.*")

    jvm {
        val pluginClasspath = classpathFromClassloader(WindScript::class.java.classLoader)

        if (!pluginClasspath.isNullOrEmpty()) {
            dependencies(JvmDependency(pluginClasspath))
        } else {
            dependenciesFromCurrentContext(wholeClasspath = true)
        }
    }

    ide {
        acceptedLocations(ScriptAcceptedLocation.Everywhere)
    }
}) {
    @Suppress("unused")
    private fun readResolve(): Any = WindScriptCompilerConfiguration
}

The script works completely fine if I run it from an external host. It also works fine in IntelliJ intellisense. The only scenario it crashes with the error shown above is when I try to run it from IntelliJ (eg by running the Current File run config).

The default plugin build task then creates multiple jars in the zip, one of them is my plugin and another one is the script jar containing the script main class, compilation and eval config and other classes in the script module.

Thanks for your reply, if you need any more sources, feel free to ask, I just couldn’t think of any other relevant source.