Search code examples
kotlinmavenintellij-ideacompiler-errors

IntelliJ Kotlin Classpath: Cannot access class


I'm importing a jar from another library and overriding one of the classes directly in my source code (please don't judge) by declaring it as same class name in same package and rely in classpath priority.

When doing so the code works fine (both with mvn and IntelliJ) and if the class I code into is java then even IntelliJ editor is happy. But if I code the class in kotlin I get:

Cannot access class 'com.****.raptor.gen.models.TextualEntry'. Check your module classpath for missing or conflicting dependencies

I wasn't able to reproduce it with any random library but only with our internal library.

The code I have is more or less this:

pom.xml:

    <dependency>
      <groupId>com.****.logistics.gpltconfig</groupId>
      <artifactId>entities-java</artifactId>
      <version>1.0.4-RELEASE</version>
    </dependency>

And this java code runs and shows in the editor fine:

    CustomsForm customsForm = new CustomsForm();
    customsForm.setDeclaredItemPrice(new TextualEntry<>());
    System.out.println("done java");

But this kotlin code runs fine but shows in the editor with an error:

    val customsForm = CustomsForm()
    customsForm.declaredItemPrice = TextualEntry<String>()
    println("done kotlin")

Any suggestion on how to do to get rid of the IntelliJ editor error in kotlin?

enter image description here


Solution

  • It's a bug in IntelliJ. IntelliJ team are working to solve it.

    For the time being there is a workaround. Put the following text as first line of that file (even before package)

    @file:Suppress("MISSING_DEPENDENCY_CLASS", "MISSING_DEPENDENCY_SUPERCLASS")