Gradle Kotlin DSL: "cannot access java.lang.String" error

This is an old bug but I have no idea how to handle it:

Is there any YouTrack issue on that? I am using IntelliJ 2019.3.1, Gradle 6.0.1, JDK 1.8 and 11, Windows 10.

Many other errors IntelliJ/Gradle related are present. The project is this one: GitHub - lamba92/firebase-multiplatform

Does it only happen in the build script? We have https://youtrack.jetbrains.com/issues/KT?q=“Check%20your%20module%20classpath”%20-Resolved%20Subsystems:%20{IDE.%20Gradle}%20, but it doesn’t look the same.

Try to change your project SDK to 8 or remove .idea folder and reimport, and kill all Gradle daemons.

Well, I assure you that I have switched many JDKs and the bug was never solved.
this time I choose GraalVM with JDK8, reboot the computer and it stopped complaining, deleting .idea was not necessary.

I believe that the issue may appear again. If so I’ll update the post!
Thank you tho :slight_smile:

Ran into the same issue when updating from Kotlin 1.3.72 to 1.4.0, this is what worked for me:

  • Checkout the project again from version control, in a different location, and import it, this worked.
  • Re-open the existing project, this time the build.gradle.kts file loaded without any errors.

Also I tried a bunch of things from here, but none of it worked: jvm - Kotlin unresolved reference in IntelliJ - Stack Overflow

This is probably https://youtrack.jetbrains.com/issue/KT-41141. Please remove all empty JDKs in IDEA “Project structure | SDKs” dialog, this should help.

8 Likes

Same, I solved by closing the project, deleting .idea and re-opening it again from the gradle.build.kts

1 Like

@Alexey.Belkov

Thank you for the suggestion.
Indeed there were some empty JDK-s in the Idea.
But who produced these invalid JDKs?
IMPO there is still an issue in there.
I use the Jetbrains Toolbox for the Jetbrains IDEs installation.
And noticed that (some or all of) the invalid paths of the empty JDKs pointed to subdirectories of the Jetbrains toolbox installation root.
What do you think?
Could it be an issue in there?

Thanks

It’s still a problem of course, we will investigate it in https://youtrack.jetbrains.com/issue/KT-41141

1 Like

Oh my god, thank you so much! I was pulling my hair out over this. This fixed the issue for me.

I also installed through toolbox so I guess I was hit by the same bug.

Deleting .idea fixed this for me

In Android Studio Arctic Fox | 2020.3.1 Canary 2 I have to configure the same SDK and Project language level.
deleting .idea & .gradle folders didn’t work.

This is a recurring annoyance for me: every time I update JDKs, all my idea projects break and there is no other solution than nuking and reimporting each project.

I use sdkman and jenv to manage JDKs on my system. I routinely have LTS and development versions of JDKs and I want to be able to replace these JDKs easily without intellij freaking out.

In this case, Intellij restored broken cached values for JDKs after I deleted the .idea, .gradle and build directories of my project and reimported this.

Please consider making this less painful/tedious as this should not be this hard.

  1. Available system JDKs should be a a system wide preference and not a per project thing. Consider having a central place to manage system JDKs. Making this per project is super tedious.

  2. Projects must be linked to a valid JDK. When a JDK they are linked to disappears (which should be expected), it should fallback to whatever is the default JDK on the system. In case there is none, use the one that runs Intellij.

  3. If you want a different JDK, select one from the list of configured system JDKs. That list should only contain valid JDKs.

Same for gradle and any other SDK on the system.

I ran into this same thing today, and it took me about an hour to realize it was because I was editing a Groovy build.gradle file, and not a Kotlin build.gradle.kts file. :man_facepalming:t2: