How to have multiple files with 'main' functions in Kotlin


Python supports multiple project files capable of being the application entry point with a ‘main’ function if the file is selected as the ‘current’ file. This is useful to quickly test example apps by running them separately. 

Kotlin, apparently,  does not support this capability since there must be only one file in a project with a main function. Is there some workaround so I can have python-like running of any file that has a main in it?

1 comment

You can have the several `main` functions in the project, but they should be in different files. But you have to explicitly indicate the main class name in the build system (mainClassName = "hello.MainKt" in Gradle) to run the project from the jar file. 


Please sign in to leave a comment.