gradle kotlin Unable to get Gradle home directory

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_32768743/article/details/84647053

创建了一个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

猜你喜欢

转载自blog.csdn.net/qq_32768743/article/details/84647053
今日推荐