gradle kotlin Unable to get Gradle home directory

创建了一个gradle的kotlin版本,然后一直
gradle kotlin Unable to get Gradle home directory_第1张图片
在环境变量中加入GRADLE_HOME就好了
gradle kotlin Unable to get Gradle home directory_第2张图片
看一下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 {
    kotlinOptions.jvmTarget = "1.8"
}

其实长得和groovy的还是挺像的
接着跑了一段代码

sealed class Base
class Derived1(val d1: Int) : Base()
class Derived2(val d2: Int) : Base()

fun main(args: Array) {
    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"))

gradle kotlin Unable to get Gradle home directory_第3张图片
运行通过,输出

Hello kotlin
Derived1
Derived2

Process finished with exit code 0

你可能感兴趣的:(学习进度,编程错误,环境搭建)