10
votes

Intellij is giving me errors all around for brand new kotlin/spring project and I cannot build or run the project from the IDE.

If I do it from the command line however, there are no issues and I can build and run the app.

build.gradle

'classpath' in 'org.gradle.api.artifacts.dsl.DependencyHandler' cannot be applied to '(groovy.lang.GString)'
'apply' in 'org.gradle.api.plugins.PluginAware' cannot be applied to '(['plugin':java.lang.String])'

Controller

Cannot access class 'java.lang.String'. Check your module classpath for missing or conflicting dependencie

Type mismatch.
Required:
java.lang.String
Found:
kotlin.String

Any ideas to what may be the issue? I tried Kotlin multiplatform JVM type mismatch in InteliJ but doesn't seem to fix the issue.

UPDATE:

Cleared gradle caches, reinstalled Intellij, Import project that was created from start.spring.io with Gradle and Kotlin selected.

Using default gradle wrapper and project jdk (the path says jre)? gives me an error. Open gradle settings just opens the file explorer.

enter image description here

Using default gradle wrapper and machine local JDK same issues with the dependencies from above.

2
If it works from the command line, but not from within IntelliJ IDEA, 99% of the time that means the project is incorrectly configured in IntelliJ IDEA. Since it is a gradle project, IDEA can automatically configure itself to the gradle project. Close the project, delete the .idea directory and any .iml files in all the modules. Then recreate the project using the steps shown in the "Working with gradle in IntelliJ IDEA" video in the "Building Projects" section on the IntelliJ IDEA documentation page: jetbrains.com/idea/documentationJavaru
re import the project using gradle wrapper. dont use your local gradle distro and see if it helps. before importing remove .idea folder and .iml fileLynAs
Same issues from above.Bri6ko
@Bri6ko Did you end up solving it? As an FYI, this only happens for me when I am using OpenJDK on an Ubuntu 18.04, on Windows 10 this error does not come up.andras
@andras I did, by formatting my ubuntu partition :DBri6ko

2 Answers

7
votes

This issue comes up if you set up your own module inside IntelliJ and you think that since you are doing a Kotlin (Maven) project, the SDK should be set to Kotlin. Wrong!

The problem is shown in the first image. The project SDK is set to Kotlin.

Kotlin as the project SDK compiler

Change it to Java. Probably any 8+ Java will be good enough.

Java as the project SDK compiler

This solves the IDE errors and the compiler errors as well.

1
votes

Unset KOTLIN_HOME and other Kotlin- or Java-related settings you may have in your environment (env to check, unset NAME to unset.)

Then kill any Gradle daemon still running (pkill -f GradleDaemon) and test your Gradle build from the terminal. If all goes well, remove the .idea directory; restart IDEA, making sure to run it without the stray environment variables (for example, launch idea.sh from the terminal where you unset them); and re-import your project, with the choice of using the default Gradle wrapper.

If you need to use standalone Kotlin versions, installed for example through SDKMAN, consider taking the SDKMAN activation lines out of your shell init file (.bashrc for Bash) and into a standalone script (say, ~/bin/sdkman) that will also change your shell prompt (PS1 in Bash) to remind you that you have entered a SDKMAN-managed CLI session.