Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

I'm asking this because I see that IntelliJ's reimport button's behavior is different than that of running the mvn command with the -U argument, and it's not clear to me why.

like image 246
Johnny Avatar asked Sep 09 '15 15:09

Johnny


People also ask

What does reimport all Maven projects do?

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.

What does reload all Maven projects do in IntelliJ?

On invoking this action, IntelliJ IDEA parses the project structure in the Maven tool window. IntelliJ IDEA cannot reload just a part of your project, it reloads the whole project including subprojects and dependencies.


1 Answers

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.

like image 76
Milan Baran Avatar answered Sep 21 '22 21:09

Milan Baran