IDEA JetBrains IntelliJ - Compile error on 'make' but fine when compiled using Maven and no errors reported by IntelliJ in the class file

Viewed 48569

So I have a maven module (module-A) in IntelliJ. I recently moved some classes from it into another new maven module (module-B) and added a dependency to it. Once I had done this I also modified the signature of a method of one of the moved classes (now in module-B).

I re-imported the poms so that IntelliJ would pick up the dependency changes and ensured all Java imports for the affected files were correct again. Now when I attempt to run my webapp (which depends on the two modules) I get a compile error in a class in module-A calling the modified method of the class in module-B.

The error message is basically saying that that method doesn't exist but believes the old method still exists! I click on the 'make' error and it takes me to the line in a class in module-A calling the modified method...the weird thing is, IntelliJ knows it is fine in the file. i.e. The method is not underlined in red like a compile error would normally be, but the class file name is :(

I compiled it from the command line using 'mvn install' (having also installed module-B) and it is all successful. I have deleted the classes directory in the target of both module-A and module-B and also invalidated IntelliJ's caches and restarted...still happening...any ideas?

22 Answers

This could happen if you are using different version of java while building outside IntelljJ. My IntelliJ had java10 and I was using java8 while building at terminal. Changing java version to IntelliJ fixed this issue for me.

None of the above answers worked for me.

In my case, I had to finally create an explicit Maven Run Configuration for the module (with Command Line as "clean install") and then run it.

It is in Run > Edit Configurations

  1. close the project
  2. go-to the project folder and delete idea project file and .iws file
  3. run mvn idea:idea
  4. restart the project.

seems idea keeping the old project dependencies without cleaning even though we run file -> invalidate caches

Setting the proper Java SDK solves the issue

  • Right click on the project and select "Open Module Settings"
  • Check if you have the right Java SDK under platform settings enter image description here
  • Check the SDK under Modules enter image description here
  • Rebuild the project from "Build" menu

Delete the installation directory.

Remove the following directories:

~/.config/JetBrains/

~/.cache/JetBrains/

~/.local/share/JetBrains/

This will remove each and every configuration plus installation of jetbrains tools, be it IDEA, goland,etc. Now install everything from scratch. That's the only way it worked for me

Related