'Cannot access script base class 'org.gradle.kotlin.dsl.KotlinBuildScript'

When I create an empty project with Gradle Kotlin DSL, even without any modifications, it would prompt Cannot access script base class 'org.gradle.kotlin.dsl.KotlinBuildScript'. Check your module classpath for missing or conflicting dependencies The project can run, but the syntax highlighting and autocompletion for build.gradle.kts don't work.

What I've tried

System

IntelliJ IDEA 2020.3.1 (Ultimate Edition)
Build #IU-203.6682.168, built on December 29, 2020
Licensed to Hykilpikonna Gui
Subscription is active until November 28, 2021.
For educational use only.
Runtime version: 11.0.9.1+11-b1145.63 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 10.15.7
GC: ParNew, ConcurrentMarkSweep
Memory: 1998M
Cores: 6
Registry: debugger.watches.in.variables=false, js.debugger.webconsole=false
Non-Bundled Plugins: CMD Support, Rider UI Theme Pack, Statistic, com.alayouni.ansiHighlight, com.intellij.ideolog, net.vektah.codeglance, String Manipulation, com.alibaba.p3c.smartfox, wu.seal.tool.jsontokotlin, com.demonwav.minecraft-dev, lermitage.intellij.extra.icons, com.github.masahirosuzuka.PhoneGapIntelliJPlugin, Dart, io.flutter, deno, org.jetbrains.kotlin, com.cybrosis.catdea, siosio.kodkod, izhangzhihao.rainbow.brackets, org.jetbrains.plugins.ruby, Pythonid, org.jetbrains.plugins.vue, tv.twelvetone.intellij.plugins.intellivue, ru.meanmail.plugin.requirements


Solution 1:[1]

Answer credit to @AlexeyBelkov - Answered here: https://youtrack.jetbrains.com/issue/KTIJ-893

The syntax highlighting feature worked after:

  1. Delete ~/.gradle/caches
  2. Delete ~/Library/Application\ Support/Library/JetBrains/IntelliJIdea2020.3 (or ~/.cache/JetBrains/IntelliJIdea2020.3 for ubuntu/linux users)
  3. Delete <project dir>/.gradle
  4. Delete <project dir>/.idea
  5. Start IDEA and reimport the project.

Solution 2:[2]

In my case (the OS is Windows 10) it was enough to:

  1. Delete C:\Users\<you>\AppData\Local\JetBrains\IntelliJIdea2021.1\caches
  2. Restart IntelliJ IDEA.
  3. Click "Load Script Configurations" when it appears after re-indexing.

Thanks @MichaelBöckling for a hint!

Solution 3:[3]

Worked for me after I'd deleted:

Delete <project dir>/.gradle
Delete <project dir>/.idea

Solution 4:[4]

Mac OS:

  1. File -> Project Structure -> SDK Location -> click on Gradle Settings
  2. Modify the Gradle JDK
  3. File -> Invalidate Caches...

enter image description here

enter image description here

Solution 5:[5]

Guided Cache Recovery (IntelliJ IDEA 2021.3+)

IntelliJ IDEA versions from 2021.3 and on (as of writing, available from JetBrain's Early Access Program, or EAP) has a featured called "Guided Cache Recovery" (File, Run Guided Cache Recovery...). While I can't find any documentation yet about this feature, it appears to give the user the ability to apply diagnostic/recovery steps, one at a time, to fixing any cache issues.

For me, the problem reported by the OP was resolved at step 2: "Rescan Project Indexes".

The really cool thing about this is that, not only did it fix my problem, but IntelliJ then created an issue report with details about the problem found, and gave me the option of submitting this report to JetBrains via the crash reporter. This tells me that JetBrains appears to be serious about fixing these issues for users, and about resolving their root causes.

Permissions Issues in .idea, .gradle, or gradle

Another possible problem is permissions issues in one of the .idea, .gradle, or gradle directories. For example, running a rootfull docker container, mounting the project as a volume (for example, to run a tool like Qodana) could cause some files to become owned by root unless the appropriate Docker options are used. If this issue is noticed, reset permissions with chmod and chown and then sync again in IDEA.

Solution 6:[6]

I set the project SDK to Kotlin under Project Settings > Modules. I also set the SDK in Plaftorm Settings > SDKs although I don't know if that's required. And just in case I restarted IntelliJ with File > Invalidate Caches / Restart ...

enter image description here

Solution 7:[7]

For IntelliJ 2021.1, I had to delete the caches folder at:
~/Libary/Caches/JetBrains/IntelliJIdea2021.1/caches

Solution 8:[8]

For me, solution was to install a separate JDK version (I installed Temurin JDK 17). I then simply set it to JAVA_HOME and used it in the AS and the errors disappeared.

Solution 9:[9]

In my case, I had to install the previous IDE version (2021.1.3).