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

48,116

Solution 1

So just stated it up this morning and it's all working!

Last night what I did do was open a new project (intelliJ project) from module-A's and module-B's parent pom and successfully got it to build, possibly doing that and then opening my original project again fixed it somehow...very annoying though

Solution 2

I found out that this might help:

File -> Invalidate Caches

Solution 3

Maven Projects -> Reimport should help.

Solution 4

I spent a few hours on this same issue. All of the cleans in the world didn't help.

I deleted my out and target directory in my project and recompiled - that cleared it.

Edit: There is also a magic feature under the file menu: "Invalidate Caches / Restart" This fixes a bunch of "intellij is confused" problems.

Solution 5

Change "Java Compiler" setting in IDEA (User compiler javac in-process) to fix the problem.

Share:
48,116

Related videos on Youtube

Ed .
Author by

Ed .

Updated on April 01, 2021

Comments

  • Ed .
    Ed . about 3 years

    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?

    • Péter Török
      Péter Török over 13 years
      Have you rebuilt and redeployed your whole project?
    • Ed .
      Ed . over 13 years
      Yes tried rebuilding the whole project in IntelliJ multiple times and keep getting the same error...:(
    • Jon Onstott
      Jon Onstott about 13 years
      Does clearing your IntelliJ caches help?
  • Ed .
    Ed . over 13 years
    Sorry forgot to mention, unfortunately I have already tried multiple clean / installs of those modules and of their parent pom, also performed clean install.
  • Ed .
    Ed . over 10 years
    Thanks vibneiro but I had already done that, and mentioned that in the question; "I re-imported the poms so that IntelliJ would pick up the dependency changes"
  • C0M37
    C0M37 about 10 years
    This worked for me. I think IntelliJ gets hung up on previous versions of code that have been made. Just went through all the module directories and ran clean. Everything works again!
  • Noremac
    Noremac over 9 years
    Be careful with doing this though. See the warning on this page: jetbrains.com/idea/help/cleaning-system-cache.html
  • naXa stands with Ukraine
    naXa stands with Ukraine over 8 years
    The only thing that worked for me. What a pity, that it took a long time. =(
  • Konstantin Gribov
    Konstantin Gribov almost 8 years
    Neither mvn clean nor invalidate caches & restart works for me :(
  • gregory boero.teyssier
    gregory boero.teyssier over 7 years
    This is what fixed it for me. Thanks.
  • kraxor
    kraxor about 7 years
    IMHO, the comment by @Noremac should be included in the answer.
  • chaiyachaiya
    chaiyachaiya about 6 years
    I also did the same in the end. The cache wasn't working.
  • Dhawan Gayash
    Dhawan Gayash almost 6 years
    I wish I could give you more points for this,. I spent close to an hour on this issue. Damn!!!!