Hello everyone. Is there a way to "register" scrip...
# scripting
Hello everyone. Is there a way to "register" scripts that get compiled into some sort of META-INF file? Let me explain. I have my regular Kotlin sources that contain my good ol' .kt files, along with some
files. I would like to retrieve, at runtime, a list of all of the classes that were compiled from said
files, e.g. with their FQN in a file somewhere within META-INF (similar to (I believe?) service providers in Java). Is there a way to do this with just the script compilation configs that are offered? I'd like to do this without compiler plugins or KSP in order to keep my build process simple. Is there a way to do this? (There are multiple use cases on my end, such as doing some sort of "feature discovery" at runtime by looking at all the classes that got generated from a
file of some sort)
I cannot think of any way to achieve this without a compiler plugin or some post-processing. But the idea seems quite interesting and may also relate to some other planned features of the scripting. Could you please, create a feature request in the YT. I think that the explanation that you gave here can serve as a feature description quite well.
If you want something like ServiceLoaders but for scripts, you can probably just implement something similar:
Copy code
fun loadScripts(classLoader: ClassLoader) {
  .flatMap { it.openStream().reader().readLines() }
  .map { /* load it as script source */ }
When you write a script in
, you register it by editing
and adding the line
. And then you can load it dynamically at run time.