I started off with the tutorial for learning Kotlin in IntelliJ
.When I tried running the example i.e
fun main(args: Array) {
prin
Ok, i've been here a few times and not entirely sure how or why this happens but reading suggests its a Kotlin/JVM mismatch. I have tried a number of things mentioned on this page but not without complete success. This was the sort of symptom the IDE was displaying in the message panel after trying to run tests via the IDE. However the code panel has no red lines indicating that modules can't be found or imported or anything untoward.
My project (at time of writing this) is a gradle 4.10.2 kotlin 1.3 project in IntelliJ (IntelliJ IDEA 2018.2.5 (Ultimate Edition) Build #IU-182.4892.20, built on October 16, 2018)
For starters though, I invalidated caches and restarted. Then ran a gradle clean build. After rebuilding the project still no joy. I went into the project settings and noticed the compiler versions were not set to java 8, I set the Compiler/Kotlin/Target JVM Version and Compiler/Java/Project Byte Code to 1.8/8 (see below), then ran some tests in the IDE and we are back in business! References resolved in my case.
Sometimes this could happen because you are trying to use a project with incompatible versions of Kotlin plugin in Gradle with plugin in your IDE. Check the versions of org.jetbrains.kotlin.jvm and other Kotlin plugins in build.gradle, and version of installed kotlin plugin in your IDE, and try to make it similar:
Your Intellij IDEA plugin and the Kotlin runtime/compiler that you use in the project need to match. For example if IDE plugin is Beta 1, but your Gradle/Maven project using M12, you'll have issues exactly as you described. So check that everything lines up.
If you still have issues, with some older plugins you need to clear the caches in Intellij IDEA (file menu, Clear Caches and Restart, select option to restart).
In my case, it was a misconfigured IntelliJ instance.
Project Structure -> SDKs -> Remove and add the Java SDK again
Simplest Solution:
Tools->Kotlin->Configure Kotin in Project
Upvote if found Usefull.
If anyone stumbles across this and NEITHER Invalidate Cache
or Update Kotlin's Version
work:
1) First, make sure you can build it from outside the IDE. If you're using gradle
, for instance:
gradle clean build
If everything goes well , then your environment is all good to work with Kotlin
.
2) To fix the IDE build, try the following:
Project Structure -> {Select Module} -> Kotlin -> FIX
As suggested by a JetBrain's member here: https://discuss.kotlinlang.org/t/intellij-kotlin-project-screw-up/597