Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin & Gradle - Make sure you have kotlin-reflect.jar in the classpath

I am working on a app using Kotlin language and Gradle Build in IntelliJ IDEA IDE. I am getting following error:

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)

I have included the dependencies as mentioned in following answer Add kotlin-reflect dependency in gradle

Even I have added the jar file in libs folder but still I am getting above error at runtime.

My Gradle file is as below:

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"
}

Is there something I need to configure for Gradle Build or am I missing something?

like image 560
Rohit Gupta Avatar asked Feb 12 '18 08:02

Rohit Gupta


People also ask

What is Kotlin is used for?

Kotlin is a modern statically typed programming language used by over 60% of professional Android developers that helps boost productivity, developer satisfaction, and code safety.

Is Kotlin better than Java?

Kotlin Application Deployment is faster to compile, lightweight, and prevents applications from increasing size. Any chunk of code written in it is much smaller compared to it, as it is less verbose and less code means fewer bugs. It compiles the code to a bytecode which can be executed in the JVM.

Is Kotlin vs Python?

Python is the best dynamic language but it is worth learning a statistically typed language. Large projects demand the rigour of a statically typed language, Kotlin can provide that rigour with no drawbacks such as verbose syntax. Learning Kotlin will teach you more about coding.

Is Kotlin Java or Python?

What is Kotlin? Kotlin is an open-source, statically typed language based on JVM (Java Virtual Machine). It was designed by JetBrains programmers to add some advanced features to Java app development.


1 Answers

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

remove compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" from project level build.gradle

like image 68
amlwin Avatar answered Oct 14 '22 08:10

amlwin