科特林公司;Gradle-确保类路径中有kotlin-reflect.jar

科特林公司;Gradle-确保类路径中有kotlin-reflect.jar,gradle,intellij-idea,kotlin,Gradle,Intellij Idea,Kotlin,我正在使用Kotlin语言和IntelliJ IDEA中的Gradle构建开发一个应用程序。我遇到以下错误: 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 ko

我正在使用Kotlin语言和IntelliJ IDEA中的Gradle构建开发一个应用程序。我遇到以下错误:

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)
我已经包括了以下答案中提到的依赖项

即使我在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配置一些东西,或者我缺少一些东西?

Build.Gradle(模块:app)中添加
实现“org.jetbrains.kotlin:kotlin reflect:$kotlin_version”


从项目级
build.gradle

删除
compile“org.jetbrains.kotlin:kotlin reflect:$kotlin_version”
是否在IntelliJ中重新导入了修改后的
build.gradle
文件?上述答案也适用于定制的gradle构建插件,如果出现一些错误,比如
KotlinReflectionNotSupportedError
。对于kotlin-gradledsl,假设您有
plugins{kotlin(“jvm”)版本“$kotlin_version”}
,那么您可以说
依赖项{compile(kotlin(“reflect”)}