1.仓库地址以 http 开头均无法连接
(1)异常描述
在 Maven 3.8.0 及以上版本中,连接 Http 开头的代码仓库会报错无法连接:
Since Maven 3.8.1 http repositories are blocked.
(2)异常分析
Maven 官网张贴了告示,在 3.8.0 版本起,会默认开启 Https 验证,所有 Http 代码仓库都将被拦截,见 Maven 官网 guide-mirror-settings:
- since Maven 3.8.0,
external:http:*
matches all repositories using HTTP except those using localhost.
(3)异常解决
一般有三种方法,将代码仓库升级 Https,降级 Maven 版本到 3.6.3 及以下,关闭 https 验证。
其中,方法一大多需要系统做较大范围迁移,尤其是企业级代码成本与周期都较高,方法二不涉及新特性使用完全可以,方法三则将 settings.xml
的 mirror
属性注释掉即可,如下:
<mirror>
<id>maven-default-http-blocker</id>
<mirrorOf>external:http:*</mirrorOf>
<name>Pseudo repository to mirror external repositories initially using HTTP.</name>
<url>http://0.0.0.0/</url>
<blocked>true</blocked>
</mirror>
2.始终更新不了远程仓库代码
注意是否开启了 off-line 模式,要么在 settings.xml 内做了配置,要么在 IDE 里开启了离线模式,如 IDEA 开启了 Work offline
属性。