60

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
4

14 Answers 14

50

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.
10
  • 8
    It seems deleting C:\Users\<you>\AppData\Local\JetBrains\IntelliJIdea2021.1\caches fixes the issue. Apr 13, 2021 at 15:37
  • 4
    After doing this something improved, maybe, but I still had all KTS files "red". For Android Studio the solution was: I went to: File -> Project Structure -> SDK Location -> "JDK Location" textbox: replace default "Embedded JDK" with a path to the separately downloaded Open JDK 11 resolved the issue. More info: youtrack.jetbrains.com/issue/KT-41141
    – yvolk
    May 27, 2021 at 4:35
  • 1
    All I had to do was update the JDK as described by @yvolk above. The other suggestions (though generally helpful in these kinds of situations) wasn't the issue here.
    – arberg
    Jun 2, 2021 at 11:10
  • 2
    For AndroidStudioPreview2021.1 deleting ~/Library/Caches/Google/AndroidStudioPreview2021.1/caches worked
    – a.r.
    Dec 3, 2021 at 6:00
  • I like your (currently deleted) suggestion for commit count. Don't forget to add, since Git 2.34, the option --unsorted-input, for an even faster result.
    – VonC
    Jul 24, 2022 at 4:53
16
  1. Close the Android Studio. (Mine was version 2021.2).
  2. Delete jdk.table.xml from Android studio's config folder .
  3. Open Android Studio and configure JDK in Gradle Settings (Project Structure -> SDK Location -> Gradle Settings).

Found the solution from JetBrain's issue tracker.

6
  • 1
    This should be marked as answer, deleting cache solves the problem only temporary.
    – Calin
    Aug 22, 2022 at 10:43
  • yes, this is correct -- the config folder needs cleaning and other answers don't mention that Sep 9, 2022 at 7:52
  • after everything with deleting caches etc. failed, simply renaming jdk.table.xml helped (note: I didn't delete <project dir>/.idea for some reason)
    – Harald
    Mar 23 at 18:07
  • you save my life
    – Junerver
    May 10 at 0:16
  • 2
    Thanks! I just add some additional info about path: {config_path}/options/jdk.table.xml
    – STAYER
    Jun 22 at 10:57
15

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!

1
  • Wow this solved my issue, also had to set the JDK in Project Structure dialog
    – abd3lraouf
    Dec 10, 2021 at 9:14
8

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

1
  • 2
    This one worked for me on Windows! Thanks for the hint. Feb 26, 2022 at 11:47
4

Worked for me after I'd deleted:

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

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.

2

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

1

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

0

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.

0

In my case I had to set the Java version in IntelliJ -> Settings -> Build -> Gradle to 1.8 to match the projects Java version

0

You need to delete de cache at

~/.gradle/caches

But an easier way is to do it from IDE, under file menu you will find "Invalidate Caches" option

Hope it works for you

enter image description here

1
  • AFAIK, gradle caches are not removed by IDE, including this Invalidate&Restart menu item. Jun 26 at 15:17
0

My solution is as shown below

I tried but The method below didn't work. use in android studio android ver AndroidStudio2022.1

  1. remove ~/Library/Caches/Google/AndroidStudio2022.1/caches
  2. remove /.gradle/caches
0

In the latest IntelliJ/Android Studio versions they've added a new action called "Repair IDE".
By running that, it incrementally does more steps that could potentially fix such issues for you.
I was experiencing this issue for example, and after clicking the automatic actions 3 times, where it reopened my project, this was fixed. I would really recommend you try out that action next time you feel like your IDE is in an odd state.

-3

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

3
  • What version was that?
    – jaco
    Jul 29, 2021 at 16:07
  • The version is 2021.1.3. Jul 30, 2021 at 5:30
  • In addition. Sometimes, projects may be "broken" after automatic updates. So, I`m trying to install IDEs manually. Jul 30, 2021 at 5:36

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.