如何让 IntelliJIDEA 从 Maven 更新我的依赖关系?

当我在项目的 < em > pom.xml 中手动添加依赖项时,让 玛文下载依赖项并让 情报构建模块,情报会抱怨缺少库。同时,玛文可以找到相关的 JAR 并构建项目。

我如何告诉 情报使用由 玛文下载的库?

195661 次浏览

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

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.

Uncheck

"Work Offline"

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

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

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.

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

That worked for me.

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

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.

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

Auto-Reload Settings

Then check "Any Changes":

enter image description here

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

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