micartey
micartey

Reputation: 174

Kotlin Script Exception in BasicJvmScriptEvaluator

I am trying to use scripts in my project using Kotlin scripts. I followed the official kotlin tutorial which works fine. Then I wanted to wrap my scripts into an object by setting the constructorArgs

private val config = createJvmCompilationConfigurationFromTemplate<MavenScriptDefinition>()

    fun evaluate(file: File, scope: Definition): ResultWithDiagnostics<EvaluationResult> {
        val host = BasicJvmScriptingHost()

        return host.evalWithTemplate<MavenScriptDefinition>(file.toScriptSource(), evaluation = {
            this.compilationConfiguration(config)
            this.constructorArgs(scope)
        })
    }

Definition is just an interface with a method greet that has been overwritten to print Hello World

This, however, results in an exception:

java.lang.IllegalArgumentException: argument type mismatch
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at kotlin.script.experimental.jvm.BasicJvmScriptEvaluator.evalWithConfigAndOtherScriptsResults(BasicJvmScriptEvaluator.kt:105)

This seems to be due to an issue inside of BasicJvmScriptEvaluator.kt which is a standard kotlin class.

I removed the constructor and all methods until I have just an empty object, everything didn't work, and the exception was the same.

The full code can be found here but keep in mind that you need to change the Core file to get it working as I use a custom classloader.

Upvotes: 1

Views: 145

Answers (0)

Related Questions