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

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

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

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


当前回答

问题似乎是,尽管在pom.xml中列出了依赖项,但IntelliJ IDEA在运行项目时并没有重新构建这些依赖项。

对我有用的是:

点击“运行”->编辑配置…,找到你的应用程序,确保“Before launch:”部分展开,点击绿色加号,并选择“Build Project”。

其他回答

如果在右下角显示“2个进程正在运行……”或类似的内容,您可能只需要等待它完成,因为下载所有的jar可能需要时间。

对于IntelliJ 2016-2.4(我相信还有其他新版本):

查看> Tool Windows > Maven项目

在新显示的工具栏中,选择Maven设置(工具集的图标)。

当这个屏幕打开时,展开Maven菜单并单击“导入”

在这里,单击“自动导入Maven项目”。还要确保“JDK for Importer”选项与您打算使用的JDK版本匹配。

单击OK。现在转到pom.xml中的红色依赖项,选择红色灯泡,然后单击“更新Maven索引”。

我能够通过在pom.xml文件中的构建标记后添加这行代码来修复我的问题,我从我的运行项目中进行比较,发现这是不同的,现在我都很好。

<repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </pluginRepository>
    </pluginRepositories>

无效缓存为我工作:

文件>使缓存失效

检查:

清除文件系统缓存和本地历史记录 清除下载的共享索引

然后无效和重新启动

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

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