从gradle任务运行kotlin应用程序的正确方法 [英] proper way to run kotlin application from gradle task
本文介绍了从gradle任务运行kotlin应用程序的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有简单的脚本
package com.lapots.game.journey.ims.example
fun main(args: Array<String>) {
println("Hello, world!")
}
这是gradle
任务
task runExample(type: JavaExec) {
main ='com.lapots.game.journey.ims.example.Example'
classpath = sourceSets.main.runtimeClasspath
}
但是当我尝试运行任务gradle runExample
时,我得到了错误
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?
推荐答案
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!")
}
和那个task
task runExample(type: JavaExec) {
main = 'com.lapots.game.journey.ims.example.Example'
classpath = sourceSets.main.runtimeClasspath
}
成功了
这篇关于从gradle任务运行kotlin应用程序的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文