在这里插入图片描述

报错信息

[ERROR] Failed to execute goal on project xxx: Could not resolve dependencies for project Failed to collect dependencies at xxx .xxx-service:jar:dev: Failed to read artifact descriptor for xxxx/maven-snapshots/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of nexus-snapshots has elapsed or updates are forced -> [Help 1]

原因分析

主模块无法识别本地的其他依赖,默认直接从服务器上获取,无论通过更新maven、修改maven配置文件,检查pom都无法解决。

解决方案

进入IDEA设置找到Runner选项

Build, Execution, Deployment --> Build Tools --> Maven --> Runner

然后将 Delegate IDE build/run actions to Maven 选项取消勾选,然后点击Apply应用保存设置即可

在这里插入图片描述

Delegate IDE build/run action to Maven

中文解释:将生成和运行操作委托给 Maven

官方解释:Delegate build and run actions to Maven

默认情况下,IntelliJ IDEA 使用原生 IntelliJ IDEA 构建器来构建 Maven 项目。如果您有一个纯 Java 或 Kotlin 项目,这可能会有所帮助,因为 IntelliJ IDEA 支持增量构建,这大大加快了构建过程。但是,如果您的配置可以动态更改编译,或者您的构建生成了具有自定义布局的工件,则 Maven 更适合构建过程。

使用 Maven 构建项目

  1. 在 Maven 工具窗口中单击在这里插入图片描述。或者,从主菜单中选择“文件”|”设置 |构建、执行、部署 |构建工具 |Maven的。

  2. 单击 Maven,然后从列表中选择 Runner。

  3. 在“运行器”页上,选择“将 IDE 生成/运行操作委托给 maven”。

    Maven Settings / Runner 页面

  4. 单击“确定”。

  5. 转到 Build |构建项目 CtrlF9.IntelliJ IDEA 调用相应的 Maven 目标。

  6. 单击在这里插入图片描述状态栏可在“生成”工具窗口中查看同步结果。

    构建工具窗口

使用 Maven 运行和调试

选择“Delegate IDE build/run action to Maven”后,IntelliJ IDEA 将使用 Maven 运行和调试代码。HotSwap 也会被触发,并且在调试过程中会重新加载类。

可以使用常规运行和调试操作,就像在任何其他项目中一样。

  1. 根据要使用的操作,从主菜单中选择“运行”|”运行或运行 |调试。

  2. 如果要调试代码,请在“运行”工具窗口或“调试工具”窗口中检查结果。例如,当您运行 main 方法时CtrlShiftF10在您的 Java 项目中,IntelliJ IDEA 使用 Maven 来运行该类。

    运行工具窗口

另外,如果是遇到Maven依赖报错:Could not find artifact XX:pom:XX ... 可以参考另一篇文章

解决Maven依赖报错:Could not find artifact XX:pom:XX …

在这里插入图片描述

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐