Matthieu Stombellini
05/16/2022, 9:37 PM.custom.kts
files. I would like to retrieve, at runtime, a list of all of the classes that were compiled from said .custom.kts
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 .feature.kts
file of some sort)ilya.chernikov
05/19/2022, 8:38 AMMatthieu Stombellini
05/21/2022, 4:26 PMTianyu Zhu
05/23/2022, 4:19 PMfun loadScripts(classLoader: ClassLoader) {
classLoader.getResources("META-INF/myScripts").asSequence()
.flatMap { it.openStream().reader().readLines() }
.map { /* load it as script source */ }
}
When you write a script in resources/path/to/myScript.kts
, you register it by editing resources/META-INF/myScripts
and adding the line path/to/myScript.kts
. And then you can load it dynamically at run time.