我正在使用Kotlin语言和IntelliJ IDEA IDE中的Gradle Build开发应用程序。我收到了以下错误:
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:86)
at kotlin.jvm.internal.ClassReference.getQualifiedName(ClassReference.kt:26)
at WorkerKt.main(Worker.kt:62)
我已经包含了以下答案Add kotlin-reflect dependency in gradle
中提到的依赖项即使我已经在libs文件夹中添加了jar文件,但我仍然在运行时遇到上述错误。
我的Gradle文件如下:
group 'com.working.workerhelp'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.2.21'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin'
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
我是否需要为Gradle Build配置一些东西,或者我遗漏了什么?
答案 0 :(得分:6)
在implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
build.gradle(Module:app)
从项目级compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
build.gradle