Maven: How to tell IntelliJ to update its Maven dependencies so that it reflects those in the local Maven repository?

Answered

We are using IntelliJ Idea to work on a very big, multi-module Maven project which uses versioned snapshots. For updating this project, I normally use the Maven tool window to run Maven goals like "mvn process-resources" or "mvn clean install". These commands download the newest snapshots from a corporate server (Sonatype Nexus) into the local Maven repository on my PC. From time to time, it happens that a new snapshot JAR was downloaded, but IntelliJ does not recognize this. Example:

  • the file xyz_server-MAIN-20221026.162532-1493.jar was downloaded by Maven into the local repository
  • in "Project Structure => Libraries", IntelliJ still references an older version of the JAR, e.g. xyz_server-MAIN-20221018.125908-1464-tests.jar

The only way (known to me) to solve this (apart from adding the new JAR in the project structure manually) is to click "Reload all Maven Projects" on the Maven tool window. But this will take ages, as it connects to the corporate Maven repository again and reloads loads of stuff via the network.

So my questions are:

  • Why does IntelliJ not recognize that a new snapshot was already downloaded into the local Maven repository via its own Maven integration?
  • How can I tell IntelliJ to update itself so that it recognizes the new snapshots efficiently in this case? By "efficiently", I mean without reloading all Maven dependencies via the network AGAIN. As they are already locally available, it would be much faster if I could tell IntelliJ to just look at the local Maven repository instead. But I do not know how to do that.

 

0
5 comments

The only way to tell IDE to check updated dependencies configuration is to use mentioned Reload action. Note that you can invoke it for specific Maven project only instead of the whole project: select this Maven module in Maven tool window and invoke action from the context menu.

1

What happens if I use the mentioned "Reload" action when I have gone offline with Maven? Will the reload action load the new JARs from the local Maven repository then? 

In addition to that, there is an "Update" button in the setting window for the maven repositories:

What does this button do? Does it only reindex the known Maven dependencies or will it maybe also discover the new ones in the local repository.

0

Offline mode means no network connections will be performed at all including the local network connections.

What does this button do?

For the remote repositories it downloads Maven index file. For local repository it rebuilds the Maven index file.

1

Hi Andrey,
thanks for your reply.

Offline mode means no network connections will be performed at all including the local network connections.

Ok, but does this mean when "Reload all Maven Projects" is uses if offline mode that it will work against the local repository so that all dependencies are updated? Meaning that if the local repository contains new versions of snapshot JARs which are not yet known by IntelliJ, will IntelliJ pick them up and update the dependencies?

 

0

Yes if local Maven dependency exists it should set it up.

1

Please sign in to leave a comment.