Changes to external Java library not picked up by compiler?

I'm having an odd issue in IDEA 14, and I hope it's just something I'm not understanding. I've got a Java project with external libraries (which are actually Maven dependencies). Now in some cases, if I update a dependency, I may get a compiler error in a file. For example, it may say that I'm trying to pass type X to a method expecting type Y. Further, assume the method is on a class that's contained in the Maven dependency.

This is where it gets weird. If I click on the method and jump to the source (which is in the external JAR), the type for the method argument is correct. But for some reason, my source file still has an error flag saying the type is wrong. I've tried doing a Synchronize on the file, the module, and even on the external JAR in the library section of the project tree. I also tried using the Maven panel to compile, do a clean/install, reimport the module, and even reimport all modules. The only thing that seems to occasionally work is shutting down IDEA completely and then restarting it. At that point, it does something (a re-index?) which finally gets rid of the error.

Is this normal? Is there some trick here to get IDEA to really pick up a change in an external library? The only things I've haven't tried yet are Make Module and Rebuild Project, which I'll try the next time this happens. However, that seems kind of extreme for something that sounds like it should "just work". I feel like I'm missing something here. Any help appreciated.

Thanks,

Brian 

3
5 comments
Avatar
Permanently deleted user

Hi Brian,

I'm using IDEA for a very large project with tens (~20) of maven modules. From time to time I get similar problem, which always is being resolved as I reimport the module (Maven/Reimport).
Are your modules imported from maven (.pom) files and is maven build successful, although an error is present in the editor?

Ivaylo

2
Avatar
Permanently deleted user

Yes, exactly. The IDEA modules are imported via POM, and I can build via Maven successfully, even though the IDE says there's an error. But if I try to, say, run a unit test within the IDE, that will fail. So it's like Maven is seeing the updated external dependency as it should be, but the IDE is stuck thinking the module I'm working on is looking at the old dependency. And again, I can even jump to the dependency JAR source and see that it is correct. Reimporting the Maven modules doesn't seem to help. Only a full restart of IDEA seems to do it, and even that seems to be hit or miss (I'm not sure what conditions trigger IDEA to actually reindex).

I was hoping this was a case where someone would say "oh yeah, just do so-and-so", but it sounds like this is more convoluted than that. And since there's really no IDE error, I can't provide JetBrains with much beyond what I'm describing. :-/

0
Avatar
Permanently deleted user

I would try deleting the dependencies caches that IDEA makes in C:\<USER_HOME_FOLDER>\.IntelliJIdea<VERSION>\system
I can not remember right now which was the exact folder - chaches, index, jars or other ...

0
Avatar
Permanently deleted user

Well, IDEA has an option to purge its indexes, but that nukes everything for all projects. That's pretty extreme and I see it as a last resort. If/when it pops up again, I plan to try using Make Module and Rebuild Project.

Thanks,

Brian

0

Hi,

I still have exactly this problem with the latest IntelliJ Build (Ultimate 2016.3.4). It "feels" like this problem mainly occurs after closing a project and opening another. 

  • I can always build all modules with Maven successfully
  • Starting the project (more precisely: Make) will then fail
  •  Sometimes other Maven dependencies are imported with old/wrong versions and new methods are not found
  •  Sometimes classes in packages like StringUtils cannot be found

What I usually can do:

  • When a wrong version is imported (3rd above) I have to find the wrong version in the project view -> external libaries and delete it manually. After that it's will compile successfully without any further actions
  • When a class cannot be found, the package will always be found, just not the class (4th above). Hitting "Reimport All Maven Projects" very frustrated, restarting and invalidating caches helps somewhen at a point feeling random

What I have tried/notcied

  • Always update SNAPSHOTS is activated
  • Maven auto-import is enabled
  • Checking for conflicting, transitive dependencies didn't show any problems (which should, how ever, be solved by Maven)
  • Building the module with 'mvn idea:idea' sometimes helps (but kills manuall added dependencies like a config file directory)
  • Deleting the local Maven repository doesn't help. How ever, I noticed the external library list contains wrong versions of dependencies which doesn't even exist in the repo
  • Dependencies imported with wrong version or dependencies not found at all seem to be random. Sometimes it's one of our projects/modules, sometimes a StringUtils, Spring Annotations, Lombok annotation, ... (somehow random).
  • I tried using Maven 3 bundled and the latest from maven.org, same bahavior

Any ideas what could cause the problem?

0

Please sign in to leave a comment.