so i want to do two things with kotlin scripting.....
# scripting
n
so i want to do two things with kotlin scripting.. use scripts as a more powerful configuration language loaded by my jar.. as far as i understand for that i have to use JSR scripting ? and secondary, getting IDE support , highlighting and autocompletion in .kts files that match the classpath that would be used for 1. i tried https://github.com/s1monw1/KtsRunner already but that does not give me 2. i think
d
YOu can get #2 -- mostly -- by creating a .idea project with all required dependencies then put your .kts file in src/main/kotlin
n
okay thats cool i guess, would that be able to pick up the correct
@KotlinScript
annotated Script definition based on file extensions ?
g
@Nikky yes, but you still need to create a service discovery file for auto-discovery
the compiler looks for files under
kotlin/script/templates
on the classpath and uses the name of those files as the FQNs of script templates
n
well thats easy, although i'd hope there will be a gradle plugin to create those for me
g
seems like an oddly specific job for a Gradle plugin, but I suppose you could
it's practically the same as the java se service loading mechanism https://docs.oracle.com/javase/9/docs/api/java/util/ServiceLoader.html
n
Copy code
scripts {
   register("com.something.ClassName")
}
it could also validate the annotations etc
g
yes thats a valid point
n
now.. does this work with 1.2 or only with 1.3 ?
g
since 1.2.50
n
yay
g
though maybe worth noting: code assistance in .kts files won't work until you have a compiled script template available. It can't use script template source code for code assistance yet.
so generally .kts files are all red until you've built your project once
n
thats fine, i plan to use this from different projects, as a configuration language, the users would add this is a maven dependency, definitly compiled