Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

proper way to run kotlin application from gradle task

Tags:

gradle

kotlin

I've got simple script

package com.lapots.game.journey.ims.example   fun main(args: Array<String>) {     println("Hello, world!") } 

And here is gradle task

task runExample(type: JavaExec) {     main ='com.lapots.game.journey.ims.example.Example'     classpath = sourceSets.main.runtimeClasspath } 

But when I try to run task gradle runExample I get error

Error: Could not find or load main class com.lapots.game.journey.ims.example.Example

What is the proper way to run application?

like image 951
lapots Avatar asked Sep 19 '16 14:09

lapots


People also ask

Does Gradle work with Kotlin?

Gradle is a build system that is very commonly used in the Java, Android, and other ecosystems. It is the default choice for Kotlin/Native and Multiplatform when it comes to build systems.


1 Answers

Thanks to the link how to run compiled class file in Kotlin? provided by @JaysonMinard that main

@file:JvmName("Example")  package com.lapots.game.journey.ims.example   fun main(args: Array<String>) {     print("executable!") } 

and that task

task runExample(type: JavaExec) {     main = 'com.lapots.game.journey.ims.example.Example'     classpath = sourceSets.main.runtimeClasspath } 

did the trick

like image 193
lapots Avatar answered Oct 05 '22 23:10

lapots