How can I make IntelliJ IDEA update my dependencies from Maven?
MavenIntellij IdeaMaven Problem Overview
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?
Maven Solutions
Solution 1 - Maven
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.
- Open the project view in IntelliJ
- Right click the pom.xml file and select Maven - Reimport
- If this works for you IntelliJ will add the dependencies to the project
- Check the if the dependencies you need are added in
- File - Project Structure - Project Settings - Libraries
- and File - Project Structure - Modules - Dependencies
Solution 2 - Maven
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.
Solution 3 - Maven
IntelliJ IDEA 2016
Import Maven projects automatically
Approach 1
- File > Settings... > Build, Execution, Deployment > Build Tools > Maven > Importing > check 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
Solution 4 - Maven
Solution 5 - Maven
File>Settings>Build,Execution,Deployment>Maven> Check : Always update snapshot
That worked for me.
Solution 6 - Maven
Uncheck
> "Work Offline"
in Settings -> Maven ! It worked for me ! :D
Solution 7 - Maven
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:
- Close project
- Open project clicking on
pom.xml
(not on a project directory) - Click
Open as Project
- Click
Delete Existing Project and Import
Solution 8 - Maven
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.
Solution 9 - Maven
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:
- Close the project in IntelliJ (file -> close project)
- Delete the
.idea
folder in the root folder of the project - Open the project again in IntelliJ
- Maven -> Reload All Projects
- Build -> Rebuild Project
Solution 10 - Maven
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.