How does IntelliJ's "Reimport All Maven Projects" button work?

I think you miss the part with local and remote repository.

If you run mvn -U it forces maven to download all libraries from remote repository that will be your company nexus or maven repo. The main difference with -U and without is that -U will override your local SNAPSHOT jars with remote SNAPSHOT jars. The local SNAPSHOT jars came from install and remote came from deploy command.

There will come the confusion with reimport. Reimport will load your local jars instead of remote jars, especially SNAPSHOT ones. You can enable force update snapshot in maven menu, which will enable -U switch in intellij.

Also double check that you share same .m2 directory with your system maven and intellij maven. You can see that in user setting file and compare it with command line maven. Just run mvn -X and check the settings section.

[DEBUG] Reading global settings from /usr/local/Cellar/maven/3.3.9/libexec/conf/settings.xml
[DEBUG] Reading user settings from /Users/xbaran/.m2/settings.xml
[DEBUG] Reading global toolchains from /usr/local/Cellar/maven/3.3.9/libexec/conf/toolchains.xml
[DEBUG] Reading user toolchains from /Users/xbaran/.m2/toolchains.xml
[DEBUG] Using local repository at /Users/xbaran/.m2/repository

enter image description here


asker's note for future readers

This answer did not fully explain the reimport button's behaviour, so I'm going to add my observations here for posterity.

There seems to be something going on with IntelliJ's caches (i.e., the .idea folder). using mvn clean install -U in terminal works as described here, but does not affect IntelliJ IDE; missing symbols are still described as missing. However, if I press the "magic reimport button", those missing symbols successfully resolve.

I can only assume that the reimport button is basically instructing IntelliJ to refresh its own cache, which is why there is a difference in behaviour.


If you changed the pom.xml file, IDEA needs to update the project structure. For example if you've added there some more dependencies, IDEA needs to add them as project libraries.

So "Maven > Reimport" is used exactly to that - to reimport a maven module. It does not trigger any maven commands with any arguments.

"Reimport All" does the same but for all maven modules in the project.

As a side note, instead of using those two actions, in "Settings > Build, Execution, Deployment > Build Tools > Maven > Importing" you can choose "Import Maven projects automatically". This will automatically invoke "Reimport" action when the pom.xml is changed.