我刚刚从subversion导入了一个项目到IntelliJ IDEA 11——这是一个maven项目。但是我在maven库依赖关系中有一个问题,所以我不能自动包括所有maven依赖关系- IDEA只在我打开该类时显示依赖错误/这就是我在这里得到的:

所以我想要自动添加所有依赖项-这是可能的还是我必须遍历所有类文件来识别和添加maven依赖项?!

更新:在做了一些修改之后,我发现了如何以某种方式解决我的问题。我就是这么做的:

但我认为从逻辑上讲,它不会包括和检查新的依赖关系?!在intelliJ - auto export dependencies to classpath中是否有设置区域?


当前回答

我在IntelliJ 2016.3.X中遇到了一些子依赖无法解决的问题。这可以通过在设置>构建,执行,部署>构建工具> Maven中更改Maven主目录从捆绑(Maven 3)到/usr/share/ Maven来修复。

在此之后,所有子依赖项都像以前的IntelliJ版本一样得到解决。

其他回答

我还补充了一下对我有用的东西:

进入IDE右侧边缘的Maven Projects侧栏,验证您的依赖项是否在模块下面正确列出。假设它们是,只需让IDEA重新导入(顶部的第一个按钮,看起来像两个蓝色箭头组成一个逆时针圆圈)。

一旦我这样做了,并让IDEA为我重新加载项目,我所有的依赖关系就神奇地被理解了。

作为参考:这是与IDEA 13.1.2

我遇到了同样的问题,尝试了这里提到的所有答案,没有一个有效。

简单的解决方案是到你的项目文件夹,删除所有的。idea和。iml文件,并重新启动IntelliJ ide。它的工作原理。不需要对设置做任何操作。

修复了IntelliJ 14之前的问题

文件[菜单]->设置-> maven ->导入和取消选中“使用maven3导入项目”

参考:http://youtrack.jetbrains.com/issue/IDEA-98425(可能也有一些其他的想法)

修正IntelliJ 15+

Ran into this again, with IntelliJ 15 this time, which has no "use maven3 to import" option available anymore. The cause was that sometimes IntelliJ "doesn't parse maven dependencies right" and if it can't parse one of them right, it gives up on all of them, apparently. You can tell if this is the case by opening the maven projects tool window (View menu -> Tool Windows -> Maven Projects). Then expand one of your maven projects and its dependencies. If the dependencies are all underlined in red, "Houston, we have a problem".

通过将鼠标移到项目名称本身上,您实际上可以看到真正的失败。

在我的实例中,它显示“问题:XXX没有可用版本”或“读取工件org.xy的描述符失败”。z"参考:https://youtrack.jetbrains.com/issue/IDEA-128846 而且 https://youtrack.jetbrains.com/issue/IDEA-152555

It seems in this case I was dealing with a jar that didn't have an associated pom file (in our maven nexus repo, and also my local repository). If this is also your problem, "urrent work around: if you do not actually need to use classes from that jar in your own code (for instance a transitive maven dependency only), you can actually get away with commenting it out from the pom (temporarily), maven project reload, and then uncomment it. Somehow after that point IntelliJ "remembers" its old working dependencies. Adding a maven transitive exclude temporarily might also do it, if you're running into it from transitive chain of dependencies."

另一件可能有帮助的事情是使用maven的“更新版本”,而不是捆绑的3.0.5。 为了将其设置为默认使用,关闭所有intellij窗口,然后打开首选项->构建,执行和部署->构建工具-> maven,并更改maven主目录,当你调整这个时,它应该在顶部显示“For default project”,尽管你也可以为特定的项目调整它,只要你在调整后“重新导入”即可。

清除缓存

删除intellij缓存文件夹(windows: HOMEPATH/。{IntellijIdea,IdeaC}XXX linux ~/. ideaic15)和/或卸载并重新安装IntelliJ本身。这也可以通过去文件[菜单]->无效缓存/重新启动....单击“无效并重新启动”。这将重新索引整个项目,并用IntelliJ解决许多难以跟踪的问题。

我有一个类似的问题,在我的情况下,我正在使用一个自定义设置。xml,这不是从IntelliJ选择。

解决方案: 文件>设置>构建,执行,部署> Maven:用户设置文件(在这里选择我的自定义Settings .xml)。

这个问题的一个可能的模式是,你没有连接到Nexus,基本上你想在离线模式下构建项目。但是当您导入项目时,Idea会尝试自动下载Maven依赖项。和失败。您在设置中设置了脱机工作复选框,但为时已晚:在首次下载尝试中已经出现故障。这里列出的两个选项都不能解决这个问题。相反,我做了以下事情:

第一个创建空Java(不是Maven)项目 选中Maven设置中的离线工作选项 将我的项目作为Maven模块添加到这个新项目中

这样就成功了。