Kotlin 1.3 with Gradle - "Kotlin not configured" error after marking the source root in IntelliJ
Asked Answered
E

6

27

I started from a regular non-Gradle Kotlin project. Then I decided later on to link my project to Gradle. I have set up my build.gradle.kts as mentioned in the Kotlin documentation:

plugins {
    kotlin("jvm") version "1.3.72"
}

repositories {
    mavenCentral()
}

dependencies {
    implementation(kotlin("stdlib"))
}

The build was successful. However, IntelliJ IDEA could no longer recognize my Kotlin modules (no syntax highlighting, etc.). Even the option of creating new Kotlin files was no longer available. So I thought maybe I just needed to mark the src directory as the Source Root, but the error "Kotlin not configured" appeared at the top.

Is there something wrong with my build? I'm still new to Gradle. I've tried other solutions like invalidating the cache and changing the dependencies, but none of them seemed to work.

Example answered 19/4, 2020 at 16:47 Comment(2)
I ended up recreating the project as a proper Gradle project and let Intellij generate the files, and everything is working now. One thing I've noticed though is that I placed the build.gradle.kts file that I manually created inside the src folder. Perhaps that is the issue.Example
Something else to try: Gradle > "reimport all"Gyrfalcon
C
59

I closed my project, and then I ran:

rm -rf .idea .gradle gradle

and then it worked again

Cheep answered 17/10, 2020 at 16:3 Comment(4)
this solution applies to almost all IntelliJ errorsOrdinal
specifically deleting .idea worked for me the 2 times this happened. I don't think you need to delete the gradle cache at .gradle. I'm near certain you don't need to delete the gradle wrapper in gradle. But who knows with these kind of errors!Tintoretto
I resolved this issue by exiting idea and reopening it...Crew
Thanks for the fix! I cleared out my ~/.gradle/caches folder (related to Android Studio)... I think that messed this up for my Intellij Kotlin project, but this worked. :)Clericals
N
14

I also did face this problem suddenly. I solve this by

Invalidate Caches and Restart

Go to the top left File>Invalidate Caches... It may not help in your case.

Nellenelli answered 14/4, 2022 at 13:41 Comment(0)
M
1

When I got this message, basic Kotlin code like args.isNotEmpty() was marked red, "Unresolved reference: isNotEmpty", like a mistyped name.

I tried Invalidate Caches... but it didn't change anything.

What worked for me was removing non-code files in the directory, then running main.kt, even though Idea said it had errors.

After a long compile time it gave some red error message, but the "Kotlin not configured" message was gone and everything that had been marked red before, like args.isNotEmpty(), was now recognized with proper syntax highlighting.

I ran main.kt a second time, and this time it just worked.

I can't say if removing the foreign files from the directory made any difference.

Mephitic answered 1/3, 2023 at 1:58 Comment(0)
T
1

This was recently happening to me too(using 2023.1).

I tried everything, clear gradle caches, invalidate intellij caches, and nothing worked.

In the end unlinking the gradle project from intellij and adding it again fixed it for me :)

enter image description here

Tiling answered 28/6, 2023 at 10:25 Comment(2)
Can you elaborate on exactly what is meant by "unlinking"?Ketchum
@Ketchum I added a screenshot, does this help?Tiling
E
0

This happened to me while trying to convert a Java file into Kotlin, with a message saying there wasn't any configuration available.

It turned out that this was caused by having the Java file in a non-source folder.

Enterostomy answered 29/6, 2021 at 9:0 Comment(0)
G
0

I opened the Gradle menu and double clicked on "clean". The problem was solved!

Gradle menu

Gromyko answered 4/7 at 20:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.