hi everyone, is there an API i can use to compile ...
# compiler
d
hi everyone, is there an API i can use to compile a kotlin file? I am able to use the scripting api but that creates extra classes to do with scripting which i dont want
s
you can use
kotlinc
directly?
d
i could but i was hoping to do it programatically
s
you can call compiler directly and pass files I guess, as they do with gradle
h
In your application you want to instantiate a compiler, Pass it kotlin sources and have the resulting classes written to disk? There is an official dependency to do that, here's a small example how to do that http://hannosprogrammingblog.blogspot.com/2018/03/programmatically-compile-kotlin-code.html?m=1 caution though, i am the author and the post is a bit old, the api has probably changed
t
You can use my library to do it: https://github.com/tschuchortdev/kotlin-compile-testing If you want to run Kotlinscript then it's probably not the best choice but for regular Kotlin code I'm not aware of any better library.
🔝 1