gradle
  • kotlin
  • 2016-09-19 187 views 6 likes 
    6

    科特林应用正确的方法我已经有了简单的脚本运行的gradle从任务

    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我得到错误

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

    什么是正确的WA ❖运行应用程序?

    +4

    的可能的复制[如何运行科特林编译后的class文件?(http://stackoverflow.com/questions/9355690/how-to-run-compiled-class-file-in-kotlin) –

    +1

    有一个关于使用Gradle应用程序插件运行Kotlin应用程序的部分:http://stackoverflow.com/a/26402542/3679676 ...或者你是否需要它运行 - 如果它是一种其他方式的任务?但是这个答案也可以给你你需要的线索。 –

    回答

    3

    感谢链接how to run compiled class file in Kotlin?通过@JaysonMinard 是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 
    } 
    

    的伎俩

    0

    您还可以应用的Gradle插件此。

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

    添加到您的build.gradle

    // build.gradle 
    apply plugin "application" 
    mainClassName = 'com.lapots.game.journey.ims.example.ExampleKt' 
    

    然后运行你的应用程序如下。

    ./gradlew run 
    
    相关问题