Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check your module classpath for missing or conflicting dependencies [closed]

I have a project with Java and Kotlin, which I am able to successfully run and build. However, when I open the project in IntelliJ, I see the same error in many of the project files.

The error is "Cannot access class 'java.lang.String'. Check your module classpath for missing or conflicting dependencies"

See the error in the image attached: enter image description here


Another example of an error occurs when initializing a Kotlin MultiPlatform Mobile project:

cannot access 'java.lang.Object' which is a supertype of 'org.gradle.api.artifacts.dsl.RepositoryHandler'. Check your module classpath for missing or conflicting dependencies

What is the source of this error? How can I fix it?

like image 340
MadLax Avatar asked May 12 '18 08:05

MadLax


2 Answers

If your project is set with a JDK, then probably IDE (Intellij) does not have JDK set but your built application could run just fine with the required JVM. Open the project structure window (ctrl + shift + alt +s) and select the java version you created your project with.

like image 99
dexter2305 Avatar answered Oct 08 '22 03:10

dexter2305


In our project we encountered this because we added the same directory to both production and the test sources.

sourceSets {
  main.java.srcDirs += 'src/main/kotlin/'
  main.java.srcDirs += 'build/generated/source/protos/main/java'
  test.java.srcDirs += 'src/test/kotlin/'
  test.java.srcDirs += 'build/generated/source/protos/main/java'
}

Removing the duplicate from the test sources fixed the problem.

sourceSets {
  main.java.srcDirs += 'src/main/kotlin/'
  main.java.srcDirs += 'build/generated/source/protos/main/java'
  test.java.srcDirs += 'src/test/kotlin/'
}
like image 22
Jesse Wilson Avatar answered Oct 08 '22 04:10

Jesse Wilson