背景
在内网开发环境没有maven仓库,只有本地maven依赖导入项目时尝尝会提示从远程仓库下载失败。Cannot access alimaven (https://maven.aliyun.com/repository/central) in offline mode and the artifact com.alipay.sofa:rpc-enterprise-sofa-boot-starter:jar:2.3.3 has not been downloaded from it before. -> [Help 1]
解决办法
修改maven config 文件
这里提供一个最简的配置,只有本地仓库配置,没有远程仓库
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>F:\out\repo_local</localRepository>
<pluginGroups></pluginGroups>
<proxies></proxies>
<servers></servers>
<!-- 完全清空mirrors,不使用任何镜像 -->
<mirrors></mirrors>
<!-- 完全清空profiles,不使用任何远程仓库 -->
<profiles></profiles>
<activeProfiles></activeProfiles>
<!-- 强制离线模式 -->
<offline>true</offline>
</settings>
清除仓库中的_remote.repositories
_remote.repositories 文件是 Maven 的本地仓库元数据文件,它记录了某个依赖是从哪个远程仓库下载的。
可通过脚本批量清除。数据无价,记得备份
find F:\out\repo_local -name "_remote.repositories" -type f -delete