我有这两个用groovy编写的gradle任务,我找不到如何将它们重写为Kotlin的正确方法:
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = "1.8"
}
}
task clearAppCache(type: Exec) {
def clearDataCommand = ['adb', 'shell', 'pm', 'clear', 'io.hruska.pocketplay']
commandLine clearDataCommand
}
我特别不确定如何替换“commandLine”方法以及如何向task添加“type:Exec”参数。
我相信以下应该可以做到这一点:
tasks {
// will need to import KotlinCompile or use the fully qualified name
withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
register<Exec>("clearAppCache") {
commandLine = listOf("adb", "shell", "pm", "clear", "io.hrushka.pocketplay")
}
}
一些链接:
1.将示例代码块从Groovy切换到Kotlin。