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
shikasd
06/17/2020, 1:23 PM
you can use
kotlinc
directly?
d
Daren Klamer
06/17/2020, 2:00 PM
i could but i was hoping to do it programatically
s
shikasd
06/17/2020, 2:39 PM
you can call compiler directly and pass files I guess, as they do with gradle
h
Hanno
06/17/2020, 5:02 PM
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
tschuchort
06/20/2020, 7:51 PM
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.