What's the best way to run an individual kotlin fi...
# intellij
b
What's the best way to run an individual kotlin file as a jvm application from the command line using
./gradlew
? I have a few sandboxes where I separate out specific parts of a library I am trying by file. Each file has its own
fun main(args: Array<String>)
m
Application plugin? Although I'm not sure that's exactly what you're looking for, as you have to configure the main class in the build.gradle, and it sounds like you have multiple files you want to 'test'. Depending on your purpose of having the various files, have you considered using tests instead? Or Running the files from an IDE like IntelliJ?
b
Using tests could be a good option. I am running the files directly from intellij right now; out of curiosity, I'd like to know what is happening when I opt to run a specific kotlin file. I imagine something like
Copy code
java -cp jarname.jar ClassNameKt
m
If you're asking what I think you're asking, the Kotlin compiler creates Java bytecode. Then java is just running that bytecode, but the main method ends up in a class created by the Kotlin compiler, and it puts the 'Kt' suffix on it. Is that sufficient info?
b
I understand that yup, just was wondering what the ./gradlew equivalent of
java -cp
is. Would just use
java -cp
but I need to compile dependencies as well.
image.png
Updated my build.gradle based on https://stackoverflow.com/a/21360609/546901 and running
./gradlew -PmainClass=KtorKt run
does the trick.
m
Yes, Application plugin is the way to go. Hadn't thought about making make a property for mainClass. Nice!