Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij issue resolving dependency for spring kotlin

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.

like image 368
Bri6ko Avatar asked Aug 05 '18 19:08

Bri6ko


2 Answers

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.

like image 83
andras Avatar answered Oct 23 '22 01:10

andras


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.

like image 31
Tobia Avatar answered Oct 22 '22 23:10

Tobia