100

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?

tmarwen
  • 15,750
  • 5
  • 43
  • 62
Jan H
  • 4,287
  • 5
  • 24
  • 34
  • 1
    Possible duplicate of [Force Intellij IDEA to reread all maven dependencies](http://stackoverflow.com/questions/9980869/force-intellij-idea-to-reread-all-maven-dependencies) – LoganMzz May 11 '17 at 07:38
  • Modern versions of Intellij prompts in a baloon to import changes or enable auto import. – Thorbjørn Ravn Andersen Oct 29 '17 at 13:49
  • Does this answer your question? [How to disable Maven auto import automatically in IntelliJ IDEA?](https://stackoverflow.com/questions/26099526/how-to-disable-maven-auto-import-automatically-in-intellij-idea) – rogerdpack Feb 11 '22 at 21:04

12 Answers12

69

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 or Maven > Reload (for newer versions of IntelliJ)
  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
Raedwald
  • 46,613
  • 43
  • 151
  • 237
Jan H
  • 4,287
  • 5
  • 24
  • 34
48

You don't have to reimport manually each time. You can enable auto-import as documented here. Change this in Settings -> Maven -> Import Maven projects automatically.

Daniel Kaplan
  • 62,768
  • 50
  • 234
  • 356
  • 20
    In later versions of IntelliJ, the option can be found under File -> Setttings -> Build, Execution, Deployment -> Build Tools -> Maven -> Importing. – Steve Chambers Apr 16 '18 at 14:35
  • 16
    This has now gone away (2020.1), and you have to click the maven button that appears over the pom file while you're editing it :( – Antony Stubbs May 21 '20 at 17:10
  • see https://stackoverflow.com/questions/26099526/how-to-disable-maven-auto-import-automatically-in-intellij-idea#comment109512099_26099587 – Antony Stubbs May 21 '20 at 17:20
  • @AntonyStubbs interestingly for me nothing seems to appear...well a small icon that seems to indicate an auto-update, but any added dependency is only available after manual reload. Seems to me like the fully automated new way is still a bit buggy... or I'm missing something... ah, you already linked to the changes in the other answer, so for anyone following up, checkout: https://blog.jetbrains.com/idea/2020/01/intellij-idea-2020-1-eap/?_ga=2.166486142.1328458743.1589984167-1329951468.1589984167#maven_and_gradle_importing_updates – Frank Hopkins Aug 08 '20 at 14:22
  • 1
    @FrankHopkins yeah in 2020.1 you have to click that button manually when it appears. The only automated maven update is when the files change outside of idea (like you check out a different branch). It's been put back in 2020.2 but you have to _turn on the setting_ - see the issue here: https://youtrack.jetbrains.com/issue/IDEA-235459#focus=Comments-27-4302337.0-0 – Antony Stubbs Aug 08 '20 at 14:25
  • 2
    @AntonyStubbs ah great! thanks for the info! It's funny, I never had issues with clicking on the notification window, but the little button that was supposed to be less obstructive is so unobstructive I didn't even notice it until I started looking as to why it didn't work anymore. – Frank Hopkins Aug 08 '20 at 14:26
28

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

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
  • 1
    I don't see Maven option after right clicking project folder. Do I need to install Maven plugin separately with IDEA ? – vikramvi Aug 29 '17 at 13:35
  • 1
    @vikramvi yes you need to install maven first. https://docs.wso2.com/display/IS323/Installing+Apache+Maven+on+Windows I might be too late but I'm adding this comment for the ones who will face it in the future. – Ish Sep 02 '21 at 07:51
  • I'm using _ideaIU-2021.2_ and this `reimport` shows as `reload`. – Ish Sep 02 '21 at 07:57
19

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

Auto-Reload Settings

Then check "Any Changes":

enter image description here

Eyal Sooliman
  • 1,876
  • 23
  • 29
  • 2
    For macOS users, beside above entry point from Maven on the right side of the IDE, you can: IntelliJ IDEA -> Preferences... -> Build, Execution, Deployment -> Build Tools -> check "Reload project after changes in the build scripts" and select "Any changes". Works for my IntelliJ IDEA 2021.1.1. – fishstick Jul 08 '21 at 20:33
10

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

That worked for me.

aevin
  • 167
  • 3
  • 16
  • 1
    For me too. *IntelliJ* is too intelligent to succeed where `Eclipse` and `mvn clean install` on a command line are able too. Hours lost. I hate pedantic software. – Marc Le Bihan Oct 05 '20 at 04:39
9

Uncheck

"Work Offline"

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

nicou50
  • 402
  • 4
  • 5
4

I tried absolutely everything to get IntelliJ to pickup my pom.xml changes but it just wasn't doing it. I commented out all of the <dependencies> in pom.xml and rebuilt the project which should've shown hundreds of compile errors but didn't.

In the end, I had to delete the .idea folder to get IntelliJ to regenerate it's maven model. Once I did this, subsequent changes to pom.xml were picked up when I did a "Reload All Projects" so I suspect a bug where IntelliJ is using a cached model rather than updating it when changes are made.

Here's what I did:

  1. Close the project in IntelliJ (file -> close project)
  2. Delete the .idea folder in the root folder of the project
  3. Open the project again in IntelliJ
  4. Maven -> Reload All Projects
  5. Build -> Rebuild Project
lance-java
  • 25,497
  • 4
  • 59
  • 101
4

Todays, there is a Reload Project option under the Maven tab when you do mouse right-click inside the pom.xml file.

Reload Maven dependencies

3

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

k13i
  • 4,011
  • 3
  • 35
  • 63
3

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.

gitrust
  • 199
  • 1
  • 8
2

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.

user
  • 31
  • 5
0

I closed the project , removed it from recent projects, deleted the .idea dir and then re-imported the project. After that, Intellij starting re-importing the dependency.

Subra M
  • 581
  • 1
  • 8
  • 16