我有一个具有以下结构的混合Java / Kotlin项目:
用于构建它的My Gradle脚本如下所示:
buildscript {
ext.kotlin_version = '1.0.4'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: "kotlin"
apply plugin: "application"
mainClassName = "com.mycopany.App"
sourceSets {
deploy
}
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
testCompile 'junit:junit:4.11'
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
}
test.testClassesDir = project.tasks.compileTestKotlin.destinationDir
task wrapper(type: Wrapper) {
gradleVersion="2.7"
}
App.kt
是一个简单的程序:
package com.mycompany.App
class App {
fun run() {
System.out.println("Hello, Kotlin world!")
}
}
fun main(args : Array<String>) {
val app = App()
app.run()
}
当我尝试使用gradle build
构建它时,我收到以下错误消息:
16:13:16.768 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':copyMainKotlinClasses'
16:13:16.768 [LIFECYCLE] [class org.gradle.TaskExecutionLogger] :copyMainKotlinClasses FAILED
16:13:16.769 [INFO] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] :copyMainKotlinClasses (Thread[main,5,main]) completed. Took 0.042 secs.
16:13:16.770 [DEBUG] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] Task worker [Thread[main,5,main]] finished, busy: 0.28 secs, idle: 0.005 secs
16:13:16.827 [LIFECYCLE] [org.gradle.BuildResultLogger]
16:13:16.828 [LIFECYCLE] [org.gradle.BuildResultLogger] BUILD FAILED
16:13:16.829 [LIFECYCLE] [org.gradle.BuildResultLogger]
当我尝试在Eclipse(也使用Gradle)中构建它时,我得到了同样的错误。
如果我使用--stacktrace
选项运行相同的脚本,我会得到:
Caused by: java.lang.NullPointerException
at org.gradle.util.GFileUtils.mkdirs(GFileUtils.java:265)
at org.gradle.api.internal.project.taskfactory.OutputFilePropertyAnnotat
ionHandler$2$1.execute(OutputFilePropertyAnnotationHandler.java:73)
at org.gradle.api.internal.project.taskfactory.OutputFilePropertyAnnotat
ionHandler$2$1.execute(OutputFilePropertyAnnotationHandler.java:68)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(Abstra
ctTask.java:621)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(Abstra
ctTask.java:604)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecuteAction(ExecuteActionsTaskExecuter.java:80)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecuteActions(ExecuteActionsTaskExecuter.java:61)
... 57 more
我该如何解决这个问题?