[maven] How can I make IntelliJ IDEA update my dependencies from Maven?

When I manually add dependencies in the pom.xml of my project, let Maven download the dependencies and let IntelliJ build the module, IntelliJ complains about missing libraries. At the same time Maven can find the dependent JARs and build the project.

How can I tell IntelliJ to use the libs which are downloaded by Maven?

This question is related to maven intellij-idea

The answer is


IntelliJ IDEA 2016

Import Maven projects automatically

Approach 1

  • File > Settings... > Build, Execution, Deployment > Build Tools > Maven > Importing > check Import Maven projects automatically

    Import Maven projects automatically

Approach 2

  • press Ctrl + Shift + A > type "Import Maven" > choose "Import Maven projects automatically" and press Enter > check Import Maven projects automatically

Reimport

Approach 1

  • In Project view, right click on your project folder > Maven > Reimport

Approach 2

  • View > Tools Windows > Maven Projects:

    • right click on your project > Reimport

    or

    • click on the "Reimport All Maven Projects" icon:

      Reimport All Maven Projects


For some reason IntelliJ (at least in version 2019.1.2) ignores dependencies in local .m2 directory. None of above solutions worked for me. The only thing finally forced IntelliJ to discover local dependencies was:

  1. Close project
  2. Open project clicking on pom.xml (not on a project directory)
  3. Click Open as Project

List item

  1. Click Delete Existing Project and Import

enter image description here


Apart from checking 'Import Maven projects automatically', make sure that settings.xml file from File > Settings > Maven > User Settings file exist, If doesn't exist then override and provide your settings.xml file path.


It turns out IntelliJ does not pick up added dependencies from the local Maven repository. We have to tell IntelliJ to reimport the pom.xml.

  1. Open the project view in IntelliJ
  2. Right click the pom.xml file and select Maven - Reimport
  3. If this works for you IntelliJ will add the dependencies to the project
  4. Check the if the dependencies you need are added in
    • File - Project Structure - Project Settings - Libraries
    • and File - Project Structure - Modules - Dependencies

in IntelliJ 2020 in the pom.xml view one should be able to apply pom changes by following key combination: CTRG + SHIFT + O.

And as correctly commented before - IntelliJ additionally shows a balloon widget to import changes.


Uncheck

"Work Offline"

in Settings -> Maven ! It worked for me ! :D


File>Settings>Build,Execution,Deployment>Maven> Check : Always update snapshot

That worked for me.


You need to go to: Maven settings -> Auto-Reload Settings

Auto-Reload Settings

Then check "Any Changes":

enter image description here


Examples related to maven

Maven dependencies are failing with a 501 error Why am I getting Unknown error in line 1 of pom.xml? Why am I getting "Received fatal alert: protocol_version" or "peer not authenticated" from Maven Central? How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Unable to compile simple Java 10 / Java 11 project with Maven ERROR Source option 1.5 is no longer supported. Use 1.6 or later 'react-scripts' is not recognized as an internal or external command How to create a Java / Maven project that works in Visual Studio Code? "The POM for ... is missing, no dependency information available" even though it exists in Maven Repository Java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/exc/InvalidDefinitionException

Examples related to intellij-idea

IntelliJ: Error:java: error: release version 5 not supported Has been compiled by a more recent version of the Java Runtime (class file version 57.0) Error: Java: invalid target release: 11 - IntelliJ IDEA IntelliJ can't recognize JavaFX 11 with OpenJDK 11 Error: JavaFX runtime components are missing, and are required to run this application with JDK 11 ERROR Source option 1.5 is no longer supported. Use 1.6 or later Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6 How to configure "Shorten command line" method for whole project in IntelliJ intellij idea - Error: java: invalid source release 1.9 Failed to resolve: com.google.android.gms:play-services in IntelliJ Idea with gradle