How can I run kotlin script from command line?
I’m using it for some data processing (like python) and would like to keep things simple and avoid heavy machinery like maven, or gradle, only command line options.
There are two kotlin files in the play
folder
user.kt
data class User(val name: String)
play.kts
fun main() {
val user = User("Jim")
println("Hello ${user.name}")
}
It doesn’t work
kotlinc -script play.kts
error: unresolved reference: User (play.kts:4:14)
play.kts:4:14: error: unresolved reference: User
val user = User("Jim")
But if I rename it to play.kt
and run with command below it works.
kotlinc . -include-runtime -d play.jar && java -jar play.jar
Why it is so, and how to make it work?
P.S.
Ideally, would be best to avoid JAR and use incremental compilation with cache to speed it up, is it possible?