Compilation Error when trying to compile script file from Java

I’m trying to use java to compile a kotlin file generated on the fly, using the K2JVMCompiler (from kotlin-compiler v 1.2.20), but I get this error: java.lang.ClassCastException: kotlin.jvm.internal.ClassReference cannot be cast to kotlin.reflect.jvm.internal.KClassImpl

Background:

I’m using this pom: https://github.com/casz/kotlin-v1-plugin/blob/master/kotlin-plugin/pom.xml for a Jenkins plugin. I’m calling the compiler from java code. I’ve also added the kotlin-compiler dependency to my pom file. I’ve poked around other places, and I seem to be doing what they do (the exec(stream, services, args)), so I’m not sure where to go from here.

If anybody could shed light on why I’m getting that error, it’d be much appreciated.