Kotlin&Gradle - 确保在类路径中有kotlin-reflect.jar

问题描述 投票:4回答:1

我正在使用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配置什么,还是我错过了什么?

gradle intellij-idea kotlin
1个回答
6
投票

implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"添加build.gradle(Module:app)

从项目级别compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"中删除build.gradle

© www.soinside.com 2019 - 2024. All rights reserved.