[英]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.当我在项目的pom.xml中手动添加依赖项时,让Maven下载依赖项并让IntelliJ构建模块, IntelliJ抱怨缺少库。 At the same time Maven can find the dependent JARs and build the project.
同时Maven可以找到依赖的JARs并构建工程。
How can I tell IntelliJ to use the libs which are downloaded by Maven ?如何告诉IntelliJ使用Maven下载的库?
It turns out IntelliJ does not pick up added dependencies from the local Maven repository.事实证明,IntelliJ 不会从本地 Maven 存储库中获取添加的依赖项。 We have to tell IntelliJ to reimport the pom.xml.
我们必须告诉 IntelliJ 重新导入 pom.xml。
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.
在设置 -> Maven -> 自动导入 Maven 项目中更改此设置。
Approach 1方法一
File > Settings... > Build, Execution, Deployment > Build Tools > Maven > Importing > check Import Maven projects automatically文件>设置... >构建、执行、部署>构建工具> Maven >导入> 勾选自动导入 Maven 项目
Approach 2方法二
Approach 1方法一
Approach 2方法二
Uncheck取消选中
"Work Offline"
“离线办公”
in Settings -> Maven !在设置-> Maven 中! It worked for me !
它对我有用! :D
:D
File>Settings>Build,Execution,Deployment>Maven> Check : Always update snapshot文件>设置>构建、执行、部署>Maven>检查:始终更新快照
That worked for me.那对我有用。
For some reason IntelliJ (at least in version 2019.1.2) ignores dependencies in local .m2
directory.出于某种原因,IntelliJ(至少在 2019.1.2 版本中)忽略了本地
.m2
目录中的依赖项。 None of above solutions worked for me.以上解决方案都不适合我。 The only thing finally forced IntelliJ to discover local dependencies was:
最终迫使 IntelliJ 发现本地依赖项的唯一事情是:
pom.xml
(not on a project directory)pom.xml
打开项目(不是在项目目录上)Open as Project
Open as Project
Delete Existing Project and Import
Delete Existing Project and Import
in IntelliJ 2020 in the pom.xml
view one should be able to apply pom changes by following key combination: CTRG + SHIFT + O .在IntelliJ 2020的
pom.xml
视图中,应该能够通过以下组合键应用 pom 更改: CTRG + SHIFT + O 。
And as correctly commented before - IntelliJ additionally shows a balloon widget to import changes.正如之前正确评论的那样 - IntelliJ 还显示了一个气球小部件来导入更改。
除了检查“自动导入 Maven 项目”之外,请确保文件 > 设置 > Maven > 用户设置文件中的 settings.xml 文件存在,如果不存在,则覆盖并提供您的 settings.xml 文件路径。
I tried absolutely everything to get IntelliJ to pickup my pom.xml
changes but it just wasn't doing it.我尽一切努力让 IntelliJ 获取我的
pom.xml
更改,但它只是没有这样做。 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.我注释掉了
pom.xml
所有<dependencies>
并重建了应该显示数百个编译错误但没有显示的项目。
In the end, I had to delete the .idea
folder to get IntelliJ to regenerate it's maven model.最后,我不得不删除
.idea
文件夹才能让 IntelliJ 重新生成它的 maven 模型。 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.执行此操作后,当我执行“重新加载所有项目”时,会接收对
pom.xml
后续更改,因此我怀疑 IntelliJ 使用缓存模型而不是在进行更改时更新它的错误。
Here's what I did:这是我所做的:
.idea
folder in the root folder of the project.idea
文件夹
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.