IntelliJ IDEA 使用 Maven 时不加载本地私服的最新版本快照(snapshot)JAR 包

IntelliJ IDEA 使用 Maven 时不加载本地私服的最新版本快照(snapshot)JAR 包

目录

  • [IntelliJ IDEA 使用 Maven 时不加载本地私服的最新版本快照(snapshot)JAR 包](#IntelliJ IDEA 使用 Maven 时不加载本地私服的最新版本快照(snapshot)JAR 包)
    • [1. 检查 settings.xml](#1. 检查 settings.xml)
    • [2. IDEA Maven 配置](#2. IDEA Maven 配置)
    • [3. 强制更新 Snapshot](#3. 强制更新 Snapshot)
    • [4. 使用 IDEA 的 Maven 索引](#4. 使用 IDEA 的 Maven 索引)
    • [5. 清理缓存并重启 IDEA](#5. 清理缓存并重启 IDEA)
    • [6. 检查网络设置](#6. 检查网络设置)
    • [7. 手动更新依赖](#7. 手动更新依赖)
    • 总结
    • 结果展示

以下是针对这个问题的详细解决方法:

1. 检查 settings.xml

确保你的 Maven settings.xml 文件中正确配置了私服仓库地址。通常,settings.xml 文件位于 ~/.m2/ 目录下。确认 和 部分的配置:

xml 复制代码
<settings>
    <mirrors>
        <mirror>
            <id>my-private-repo</id>
            <url>http://private-repo-url/repository/maven-snapshots/</url>
            <mirrorOf>snapshots</mirrorOf>
        </mirror>
    </mirrors>
    <profiles>
        <profile>
            <id>default</id>
            <repositories>
                <repository>
                    <id>snapshots</id>
                    <url>http://private-repo-url/repository/maven-snapshots/</url>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>snapshots</id>
                    <url>http://private-repo-url/repository/maven-snapshots/</url>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
    <activeProfiles>
        <activeProfile>default</activeProfile>
    </activeProfiles>
</settings>

2. IDEA Maven 配置

确保 IDEA 中的 Maven 配置正确。

进入 Settings/Preferences -> Build, Execution, Deployment -> Build Tools -> Maven。

检查 User settings file 路径是否正确指向你的 settings.xml 文件,并确保 Override 复选框已勾选。

检查 Local repository 路径是否正确。

3. 强制更新 Snapshot

确保 Maven 在构建时强制更新 Snapshots。

进入 Settings/Preferences -> Build, Execution, Deployment -> Build Tools -> Maven -> Runner。

勾选 Force update of Snapshots/Releases。

4. 使用 IDEA 的 Maven 索引

尝试使用 IDEA 的 Maven 项目索引功能。

进入 Settings/Preferences -> Build, Execution, Deployment -> Build Tools -> Maven -> Importing。

勾选 Use Maven 3.x compiler plugin 和 Import Maven projects automatically。

5. 清理缓存并重启 IDEA

清除 IDEA 的缓存并重启。

进入 File -> Invalidate Caches / Restart... -> Invalidate and Restart。

6. 检查网络设置

确认 IDEA 能够访问到私服仓库。确保防火墙或代理设置不会阻止 IDEA 访问私服。

7. 手动更新依赖

如果上述方法仍然无效,尝试手动更新依赖。

打开终端,导航到你的项目目录。

运行以下命令:

sh 复制代码
mvn clean install -U

这将强制更新所有 Snapshots 和 Releases。

总结

通过以上步骤,应该可以排查并解决 IDEA 使用 Maven 时不加载本地私服临时版本 JAR 包的问题。

结果展示

我的IDEA版本是2024.3.4,我首先进入 Settings/Preferences -> Build, Execution, Deployment -> Build Tools -> Maven,这有个始终更新快照选项(Always update snapshots),勾选上

然后我把本地私服jar包所属文件夹删除

最后清理并重新导入 Maven 项目,在 IntelliJ IDEA 中,右键点击项目根目录中的 pom.xml 文件。

选择 Maven -> reimport,重新加载后拉取的快照版本被加载了

错误情况

正确情况


👑 天下英雄出我辈,一入江湖岁月催 我是热爱生活的「 无间行者 」,努力把实践过的解决方案分享给大家 如果这篇文章对你有用,一键三连,感谢你的鼓励,让我知道你在看


相关推荐
计算机学姐5 小时前
基于SpringBoot的美食分享交流平台
java·spring boot·后端·spring·java-ee·intellij-idea·美食
*.✧屠苏隐遥(ノ◕ヮ◕)ノ*.✧1 天前
《苍穹外卖》- day01 开发环境搭建
spring boot·后端·spring·maven·intellij-idea·mybatis
Getgit1 天前
Linux 下查看 DNS 配置信息的常用命令详解
linux·运维·服务器·面试·maven
秋91 天前
idea中如何使用Trae AI插件,并举例说明
java·人工智能·intellij-idea
Hyacinth&1 天前
IntelliJ IDEA|学习笔记
笔记·学习·intellij-idea
可以吧可以吧2 天前
idea全家桶【常见报错处理】当出现 “We could not validate your license ... “ 提示时
java·ide·intellij-idea
装不满的克莱因瓶2 天前
IDEA rebuild project 到底有什么作用?
java·ide·intellij-idea
Java程序员威哥2 天前
Arthas+IDEA实战:Java线上问题排查完整流程(Spring Boot项目落地)
java·开发语言·spring boot·python·c#·intellij-idea
摇滚侠2 天前
在 IDEA 中,GIT 合并分支时选择远程的 dev 分支和本地的 dev 分支,有区别吗
java·git·intellij-idea
tkevinjd2 天前
4-初识Maven
java·maven