IDEA JetBrains IntelliJ - Compile error on 'ma

2019-01-21 22:18发布

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?

18条回答
该账号已被封号
2楼-- · 2019-01-21 22:21

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.

查看更多
疯言疯语
3楼-- · 2019-01-21 22:21

I ran across a very similar problem that was driving me insane.

My code would compile fine with the ant task I normally run, but it would not build in IntelliJ, complaining about "Cannot Find Symbol blah blah"

Turns out, you can add "Excluded" files for the compiler. My file somehow got added to that list.

This list is located in File > Settings > Compiler > Excludes (IntelliJ 13)

查看更多
乱世女痞
4楼-- · 2019-01-21 22:21

I had a very similar behavior. Running (Scala-)tests would always fail due to errors in unrelated java classes during the 'make' step.

It turned out, I had included a 'global' SDK library that collided with one of the dependencies from the project. A proper helpful error message only showed up after I deleted the 'make' step from the test. I then deleted the duplicate library, re-added the make step to the test and everything is now working fine.

查看更多
放荡不羁爱自由
5楼-- · 2019-01-21 22:24

This happened to me...what fixed it was realising there was an extra main.iml file in the source directory. Deleting that instantly made the compile errors go away.

查看更多
看我几分像从前
6楼-- · 2019-01-21 22:25

The fix was i made it javac instead of Ajc and i put 1.8 of course according to your jdk version.

for some reason when i invalidate and restart intellij it was set to be the default !

after i fixed i made it javac instead of Ajc

my version is

enter image description here

查看更多
戒情不戒烟
7楼-- · 2019-01-21 22:26

I ran into this problem today after upgrading from 12 to 13.

Later I fixed issue as I used the same name for Project and Module and looks Intellij allows this but cannot handle it correctly.

No idea why setting will impact the compilation, although there is no error in java editor. Should be a bug in version 13.

查看更多
登录 后发表回答