Force IntelliJ to read local maven repository when it loses track of dependencies
已回答
IntelliJ frequently "forgets" or fails to detect new/updated artifacts in my local Maven repository. Is there a way to force it to check the local repo for dependencies?
The only current fix is to Invalidate caches/restart and then force reimport of the project.
请先登录再写评论。
What do you mean by "forget"? In which situation a new dependency is not updated? After a version change or else?
Have you tried re-import dependencies action? try also File | Synchronize action and ten re-import.
Do you have Settings (Preferences on macOS) | Build, Execution, Deployment | Build Tools | Maven | Always update snapshots enabled?
So it's taken a while before I saw this again, but it just did:
I've had "Always update snapshots" enabled for a long time.
>IntelliJ doesn't recognize the new class, even after reimporting project
If for the dependency you use the jar from the local Maven repository and change it's version, the jar must be first "installed" into a local Maven repository and the IDE project re-imported form Maven in order for IDE to recognize the updated jar library version.
I believe this is what's happening. I run "mvn clean install" in the dependency project, then in the main project I re-import the main project. The main project doesn't always recognize the updated dependency.
>The main project doesn't always recognize the updated dependency.
Do you mean even after Maven re-import action? Try also File | Synchronize action, then re-import. Also try using latest Maven version from https://maven.apache.org/download.cgi to set in IDE settings: Settings (Preferences on macOS) | Build, Execution, Deployment | Build Tools | Maven | Maven home directory.
If problem remains please clarify on below:
When issue happens when exact problem do you have: build fails or you see "red" code in Editor?
How do you declare the dependency in pom file (including the version format)?
Provide idea.log after IDE restart and reproducing (re-importing in Maven window). For uploading you can use ftp://ftp.intellij.net/.uploads / https://uploads.services.jetbrains.com or any file sharing service.
Yeah, I basically hit Maven reimport several times between each step. File | Synchronize didn't seem to help. The IntelliJ build fails, and there is red code marking the problem in the Editor.
I declare dependencies in the top-level pom's dependencyManagement:
and then in the child module I omit the version when using the dependency:
What IDE and Maven version do you use? There was a bug in Maven with dependencies from parent pom not detecting correctly. It was fixed in 3.6.1 version. Try using this version from https://maven.apache.org/download.cgi and set it in IDE settings.
Also try 2019.2 EAP from https://www.jetbrains.com/idea/nextversion/ it as well has related fixes.