如何强制intellij想法重读/更新pom文件中指定的所有依赖项?


当前回答

对于单独的模块:右键单击模块的pom.xml -> Reload as Maven项目。

其他回答

有两种方法可以做到。

1号路

进入文件>设置>构建,执行,部署>构建工具| Maven

选择“始终更新快照”

Apply和OK

2号路 mvn -U clean install

还有一个有用的设置告诉IntelliJ检查依赖项的新版本,即使版本号没有改变。我们有一个本地maven存储库和一个快照项目,它更新了几次,但版本号保持不变。问题是IntelliJ/Maven没有更新这个项目,因为版本号是固定的。

要启用检查变更的依赖关系,尽管版本号没有改变,请进入“Maven项目”选项卡,选择“Maven设置”,并在那里激活“始终更新快照”。

我遇到了一个问题,IntelliJ无法编译类,声称缺少项目之间的依赖关系。 按照这个问题的答案重新导入项目并不能解决问题。 我的解决方案是:

删除所有项目(项目标签/右键单击根文件夹/ maven /删除项目); 关闭编辑器; 在命令行上使用maven编译所有项目; 打开同一项目的编辑器; 再次将项目添加到maven (maven TAB /添加maven项目(绿色+)/选择根pom);

警告:在某些项目中,您可能必须增加maven导入的最大内存(maven选项卡/导入/导入器的VM选项中的maven设置)。

这在2022年仍然是一个问题。

The option Setting > Maven > Always update snapshots no longer works in IDEA 2022.2.2, probably because Maven 3 frowns upon it and IntelliJ seems to not have updated the IDE to make it function. A simple solution might be to be able to add maven -U clean install as a custom target to the Lifecycle list in the IDEA Maven tab, but if it is possible it is not clear how to do it (even after googling for days). A not as nice but viable solution would be to go into the Terminal tool of IDEA and typing maven -U clean install, but IDEA does not expose the maven command in its Terminal by default and again it is not clear how to configure it so that it would.

如果您使用IntelliJ,有四种独立的方法可以刷新maven存储库。 它们中的每一个都会刷新计算机上的另一个本地存储库,或者以不同的方式刷新它们。

1. mvn -U clean install
2. Ctrl+Shift+A - Reimport
3. Round arrows in the Maven window

4. Ctrl+Alt+S , go to Build, Execution, Deployment | Build Tools | Maven | Repositories -choose rep - update

有趣的是,人们常说,最后一次刷新等于Maven窗口中的圆形箭头。但是,根据我的经验,它们是完全不同的!证明:我们的大型项目在最后一次刷新时失败了,但是没有它也能很好地存在和运行。双圆箭头可以在上面运行。

这四种方法中的每一种都可以帮助您解决问题或/并发现自己的问题。例如,对于运行我们现实生活中的项目,第一个是必要的,但是对于IntelliJ中的测试,我们还需要2和3。当然,有人也需要4个。(要不然IntelliJ为什么有这个功能?)