2017-05-31 83 views
1

我转换简单Kitlon文件到图书馆,该文件是:添加库到摇篮科特林应用

Display.kt

package hello 

fun main(args: Array<String>) { 
    println("Hello World!")   
} 

一直在使用该命令编译成库:

kotlinc Display.kt -d Display.jar 

输出已被交叉检查以使用命令工作:

kotlin -classpath Display.jar hello.DisplayKt 

然后我把它到文件夹src/main/resources,然后试图从另一个应用程序调用它,使用下面的代码:

Hello.kt

package hello 

import hello.DisplayKt 

fun main(args: Array<String>) { 
    println("Hi")   
} 

和定义的build.gradle文件,如下(试图把所有选择我读到解决我的情况):

// set up the kotlin-gradle plugin 
buildscript { 
    ext.kotlin_version = '1.1.2-2' 

    repositories { 
     mavenCentral() 
    } 

    dependencies { 
     classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 
    } 
} 

// apply the kotlin-gradle plugin 
apply plugin: "kotlin" 


// add kotlin-stdlib dependencies. 
repositories { 
    mavenCentral() 
} 

dependencies { 
    //dependencies from a remote repositor 
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 

    //local file 
    compile files('src/main/resources/Display.jar') 
    compile fileTree(dir: 'src/main/resources', include: '*.jar') 
} 

jar { 
    manifest { 
     //Define mainClassName as: '[your_namespace].[your_arctifact]Kt' 
     attributes ('Main-Class': 'hello.HelloKt', "Implementation-Title": "Gradle", 
        "Implementation-Version": 1) 
    } 

    // NEW LINE HERE !!! 
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } 
} 

sourceSets { 
    main { 
     java { 
      srcDirs = ['src/kotlin'] 
     } 
     resources { 
      srcDirs = ['src/resources'] 
     } 
    } 
} 

但是,运行gradle build命令后,我得到了下面的错误:

Unresolved reference: DisplayKt

注:我非常非常新的JAVA /科特林和摇篮

回答

1

我找到了答案,该功能的完整路径是hello.main