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