gradle kotlin Unable to get Gradle home directory

創建了一個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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章