How to compile Kotlin Script into open (not-final) java class?

Hi folks

I have .kts files under the source directory with my own defined @KotlinScript class, so they’re going to be compiled into .class files during the build using my ScriptCompilationConfiguration implementation. And the main thing I’ve noticed is that compiler creates a final class, which extends my @KotlinScript-annotated class. What I’m really interested in is proxying these classes using some bytecode libs (CGLIB) via Spring, but, as you may know, it’s impossible to build any proxies based on final classes.
I recently found out that there’s a plugin for compiler named ‘All-open’ and, moreover, its preset is used in kotlin-spring plugin to make it possible to not declare @Configuration classes as open ones. Regardless it had already been included in my gradle project, my compiled scripts are still final. So, I came up with adding compilerOptions("-P plugin:org.jetbrains.kotlin.allopen:preset=spring") into the builder’s body of ScriptCompilationConfiguration, but still no result, generated implementations are still final. My script I want to build into the open class already has @file:SpringBootApplication annotation included, i.e. it’s meta-annotated by @Configuration.

Summarising everything above, I’d like to ask a question: is it even possible for nowadays to tell the compiler we want get scripts compiled into open classes using ScriptCompilationConfiguration or some other hacks workarounds? In my particular case with Spring, I can just set proxyBeanClass to false, but it ain’t a elegant solution though. Also, for me defining script configuration is much more interesting than simply getting things working with some additional parameters.


1 Like