gradle kotlin Unable to get Gradle home directory
阿新 • • 發佈:2018-11-30
建立了一個gradle的kotlin版本,然後一直
在環境變數中加入GRADLE_HOME
就好了
看一下kts指令碼內容
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { kotlin("jvm") version "1.3.0" } group = "cn.net.pikachu" version = "1.0-SNAPSHOT" repositories { mavenCentral() } dependencies { compile(kotlin("stdlib-jdk8")) } tasks.withType<KotlinCompile> { kotlinOptions.jvmTarget = "1.8" }
其實長得和groovy的還是挺像的
接著跑了一段程式碼
sealed class Base
class Derived1(val d1: Int) : Base()
class Derived2(val d2: Int) : Base()
fun main(args: Array<String>) {
println("Hello kotlin")
for (derived in Base::class.sealedSubclasses) {
println(derived.qualifiedName)
}
}
報錯
Exception in thread "main" kotlin.jvm.KotlinReflectionNotSupportedError: Kotlin reflection implementation is not found at runtime. Make sure you have kotlin-reflect.jar in the classpath at kotlin.jvm.internal.ClassReference.error(ClassReference.kt:79) at kotlin.jvm.internal.ClassReference.getSealedSubclasses(ClassReference.kt:45) at MainKt.main(main.kt:7)
加反射包
compile(kotlin("reflect"))
執行通過,輸出
Hello kotlin
Derived1
Derived2
Process finished with exit code 0