确保你的 Maven settings.xml 文件中正确配置了私服仓库地址。通常,settings.xml 文件位于 ~/.m2/ 目录下。确认 和 部分的配置:
<settings>
<mirrors>
<mirror>
<id>my-private-repoid>
<url>http://private-repo-url/repository/maven-snapshots/url>
<mirrorOf>snapshotsmirrorOf>
mirror>
mirrors>
<profiles>
<profile>
<id>defaultid>
<repositories>
<repository>
<id>snapshotsid>
<url>http://private-repo-url/repository/maven-snapshots/url>
<snapshots>
<enabled>trueenabled>
snapshots>
repository>
repositories>
<pluginRepositories>
<pluginRepository>
<id>snapshotsid>
<url>http://private-repo-url/repository/maven-snapshots/url>
<snapshots>
<enabled>trueenabled>
snapshots>
pluginRepository>
pluginRepositories>
profile>
profiles>
<activeProfiles>
<activeProfile>defaultactiveProfile>
activeProfiles>
settings>
确保 IDEA 中的 Maven 配置正确。
进入 Settings/Preferences -> Build, Execution, Deployment -> Build Tools -> Maven。
检查 User settings file 路径是否正确指向你的 settings.xml 文件,并确保 Override 复选框已勾选。
检查 Local repository 路径是否正确。
确保 Maven 在构建时强制更新 Snapshots。
进入 Settings/Preferences -> Build, Execution, Deployment -> Build Tools -> Maven -> Runner。
勾选 Force update of Snapshots/Releases。
尝试使用 IDEA 的 Maven 项目索引功能。
进入 Settings/Preferences -> Build, Execution, Deployment -> Build Tools -> Maven -> Importing。
勾选 Use Maven 3.x compiler plugin 和 Import Maven projects automatically。
清除 IDEA 的缓存并重启。
进入 File -> Invalidate Caches / Restart… -> Invalidate and Restart。
确认 IDEA 能够访问到私服仓库。确保防火墙或代理设置不会阻止 IDEA 访问私服。
如果上述方法仍然无效,尝试手动更新依赖。
打开终端,导航到你的项目目录。
运行以下命令:
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,重新加载后拉取的快照版本被加载了


