ChatGPT解决这个技术问题 Extra ChatGPT

Force Intellij IDEA to reread all maven dependencies

How to force intellij idea to reread/update all dependencies specified in the pom file ?


j
jeninja

Press Ctrl+Shift+A to find actions, and input "reload", you will find the "Reload All Maven Projects".

On a Mac, use ⌘+⇧+A instead.


Lets say I have 5 modules, all of them maven based, in a single project and I do this. Does this command apply to all modules, just the selected one, or the first one in the project when it runs?
has this changed? I do not see a reimport on 2017.1 in Maven
@Winnemucca I just did it on 2017.2. Waiting for it to finish now.
At the time of this writing, it is now called "Reload all Maven Projects".
Is this renamed to "reload all maven projects"?
k
kubek2k

Open the "Maven Projects" tab/window and clicking the "Reimport All Maven Projects" in the upper left corner starts to reload all dependencies from their repositories. The status bar informs about the process.

What lets you think that this is not working correctly? Maybe any of the dependencies can't be load from the repository?


we have a broken habit of using a non-snapshot version for on-going development, and cross-project dependencies sometimes fail.
I'm afraid this problem depends on maven. Maven only checks for updates on SNAPSHOTs. Per definition, non-SNAPSHOT versions will never change so maven don't has to check for newer versions than this in the local repository. A (quite rude) solution would be to remove the library from the local repository before invoke maven. Then it has to reload the library.
it appears that the reimport all forces the -U flag what is what I wanted :)
I was right-clicking the parent project and doing Maven -> Reimport and hoped it'll update the dependencies of all the children, but it did not. Thanks for the solution!
To find the "Maven Projects" tab/window go to View > Tool Windows > Maven Projects
B
Björn Jacobs

There is also one useful setting that tells IntelliJ to check for new versions of dependencies even if the version numbers didn't change. We had a local maven repository and a snapshot project that was updated a few times but the version numbers stood the same. The problem was that IntelliJ/Maven didn't update this project because of the fixed version number.

To enable checking for a changed dependency although the version number didn't change go to the "Maven Projects" tab, select "Maven settings" and there activate "Always update snapshots".


ha! automated updates in a JAVA project...I'm going to have to say this one is NOT always a winner...and may even be frowned up w/ Maven 3+
@beauXjames.. this didn't work for me but I am exactly facing the same issue. how to resolve this.
I often go into the local repo ({user}\.m2\...) directory and delete those I know are associated with my project then let the install process go out and fetch them again from scratch so there's no version conflicts
From help: "Select this checkbox, if you want IntelliJ IDEA to update snapshots on sync." In other words, it isn't fully automatic -- you have to Synchronize (in right-click menu or Ctrl-Alt-Y), but enabling this option causes it to grab updated SNAPSHOT versions. WARNING: There may be other subtleties involved, like Import Changes -- this doesn't seem to be perfectly reproducible for me so far. Maybe it was all in my imagination -- what does always seem to work is a full reimport as suggested in other answers.
t
teejay

For IntelliJ IDEA 14.0

Project > [your project name] > right click > Maven > Reimport


U
Umut Uzun

The leftmost button (blue cycle) below also reimports all maven projects:

https://i.stack.imgur.com/JHIl9.png


Thanks for this comment. I see too few answers on this post that contain the word "Reload", which in this case seems to do the same thing as what I guess "Reimport" used to do.
B
Babajide Apata

run this command mvn -U clean install


While this is a solution, it needs to be done from the CLI. The question is about doing it from inside IDEA.
on the IDE, you can execute a maven goal and use the command above without you opening your CLI or Terminal
That kinds of defeats the purpose of having maven integration in IDEA.
We are talking about the -U option, which is not present in IDEA. The "Reimport" option sounds like it is, but it's not.
I see that you are referring to typing and executing a maven goal, in which case it's possible. However, I was referring to -U not being present in the built-in menu on the right ("Maven Projects").
A
Andreas Dolk

If the reimport does not work (i.e. doesn't remove old versions of dependencies after a pom update), there is one more chance:

open the project settings (CTRL+SHIFT+ALT+S)

on modules, delete all libs that you want to reimport (e.g. duplicates)

IDEA will warn that some are still used, confirm

Apply and select OK

then reimport all maven projects.


Thanks, this works, although now the library doesn't show up under "External Libraries" at all, but the project is using the new library successfully anyway. I wonder what is wrong with IntelliJ when it can't update the External Libraries section to match the reality.
n
nobjta_9x_tq

Setting > Maven > Always update snapshots


Works for me using IJ 2020.3.2
Only this option works for me to force Maven to download the latest JAR from a remote source instead of using the one in the local .m2 repo
D
Drunken Daddy

In the latest IntelliJ IDEA version (2020.1.3 Ultimate Edition), You need to to click this little guy that appears on the top right of the editor window after you make a change to the pom.xml

This little guy is too small and in an unnoticeable position. I liked the previous versions where an alert shows up in the bottom right. Still can't find the option to enable auto import in this version.

https://i.stack.imgur.com/bKPIz.png

Another Option

From the properties panel on the right, select Maven and click on the reload icon. If you do not see maven on right panel, open it from View > Tool Windows > Maven

https://i.stack.imgur.com/6HnBZ.png


Thank you for this answer !!! I feel dumb for admitting that before your hint, I was basically always shutting down my entire project and re-opening it !!!
This little guy is so small that I clicked on the close btn instead and don't know how to reopen it 0.0
r
rslj

Go to File | Settings | Build, Execution, Deployment | Build Tools | Maven

Select "Always update snapshots"


K
KollKode

I had a problem where IntelliJ was unable to compile classes, claiming that dependencies between projects were missing. Reimporting the project as suggested in the answers of this question didn't solve the problem. The solution for me, was:

remove all projects (project tab / right click on the root folder / maven / remove projects); close the editor; compile all projects with maven on the command line; open the editor on the same project; add the projects to maven again (maven tab / add maven projects (green +) / choose the root pom);

WARNING: on some projects, you might have to increment max memory for maven import (maven settings on maven tab / Importing / VM options for importer).


G
Gangnus

If you work in IntelliJ, there are four independent ways to refresh maven repositories. Each of them refreshes another local repository on your computer or refreshes them differently.

1. mvn -U clean install
2. Ctrl+Shift+A - Reimport
3. Round arrows in the Maven window

4. Ctrl+Alt+S , go to Build, Execution, Deployment | Build Tools | Maven | Repositories -choose rep - update

What is interesting, it is often said, that the last refresh is equal to the round arrows in the Maven window. But, according to my experience, they are absolutely different! The proof: Our large project fails the last refresh, but exists and runs happily without it. And double round arrows run OK on it.

Each of these four can help you with your problems or/and find problems of its own. For example, for running our real-life project only the first is necessary, but for testing in IntelliJ we also need 2 and 3. Surely, somebody needs 4, too. (Why else IntelliJ has it?)


v
vegemite4me

If you are using version ranges for any dependencies, make sure that IntelliJ is using Maven 3 to import the project. You can find this setting in: Settings > Maven > Importing > Use Maven3 to import project. Otherwise you may find that SNAPSHOT versions are not imported correctly.


F
FlyOne

For separate modules: right click on modules's pom.xml -> Reload as Maven project.


佚名

To remove all dependencies you can simply delete your local maven repo: ~/.m2 folder by default. Then rebuild your projects one-by-one:

mvn clean
mvn package