I’ve been using Kotlin at work for several months now and today I tried creating a new personal project on my machine at home.
I did what I wanted to do in around an hour and spent the rest of the evening pulling my hair trying to figure out gradle and how it relates to Kotlin, IDEA and so on.
The project compiles fine and tests run successfully, however the IDE keeps complaining about missing stuff. I’ve tried adding all sort of dependencies to the gradle build file (including ones from a project that works) but nothing fixed it. I deleted everything in the project (except src), reimported it back and ended up with the same problem.
On a somewhat unrelated subject, while I like Kotlin as a language (it’s easy, obvious and predictable), gradle is exactly the opposite. The gradle DSL is horrible, unintuitive and inconsistent. On top of that, the Kotlin-Gradle DSL from “Using Gradle” page didn’t work:
Not sure about the issue from the first picture, but the in your gradle file the implementation(...) calls need to be inside of a dependencies block.
The first dependency block (within buildscript) is responsible for informing gradle about plugins and stuff used within the build.
Then you need a separate one (outside of buildscript) for the dependencies of your project.
As for gradle… it’s a mess. It’s super hard to use and mostly seems like magic to me. That said it’s still the best build tool I used so far. The documentation isn’t that great either. Still I can’t find anything wrong in the “using gradle” page you linked. What exactly there didn’t work?
I got the same error today after Intellij upgraded my bundled kotlin plugin on Mac OS. The problem might not be the same, but the error message was identical.
Turns out before my project was using JDK 11, but after the kotlin plugin upgrade the JDK was upgraded as well to 13. I resolved the issue by dropping the existing JDK 11 with the - button in the Project Structure window and then adding it again using the + button - which selected JDK 13 by default. After that this error went away.
I wouldn’t say there is anything specifically wrong, but rather incomplete or misleading.
For example, only now (and thanks to you) did I realise that the first example of “Configuring Dependencies” section puts “implementation” inside “dependencies”.
My argument would be that the article sounds like a quick intro to the topic but then it’s too exhaustive. I ended up spending quite some time trying to find a minimal “hello world”-style build.gradle(.kts) file - made worse with my other issue causing me to doubt when the setup actually works vs just some IDE complaints.
I am having a similar issue. I recently upgraded the community version from 2019 to 2020.1. I had no issues before upgrading the IDE. I attempted to update the project structure JDK. This did not solve the issue for me. What I have noticed is that the class path for the 11 JDK and Kotlin SDK that was defaulted was empty. I removed the 11 JDK and downloaded 13 as well as 14 and have tried both as the project jdk, and the error persists, I am seeing the error when it comes to enum classes.
This generally happens when there is a mismatch between JDK versions of your project and the version which is installed on your machine. Go to File->Project Structure->Project->Project SDK and make sure that you match that version to that of installed on your machine.
Thanks to tips above.
I had this problem after creating a new multimodule kotlin app using ‘gradle init’ on the command line.
The generated code was getting this error.
I resolved this problem by switching the Project Settings->Project->SDK from java 17 that intelliJ installed to temurin 17 jdk that I had installed from homebrew.