目 录CONTENT

文章目录

maven-default-http-blocker

xlong
2024-04-10 / 0 评论 / 0 点赞 / 5 阅读 / 1539 字 / 正在检测是否收录...

maven-default-http-blocker

maven从私有仓库拉取依赖包报错:

Downloading from maven-default-http-blocker: http://0.0.0.0/xx Could not transfer artifact xxx from/to maven-default-http-blocker (http://0.0.0.0/): Blocked mirror for repositories: 

原因: 如果使用HTTP协议下载依赖,可能会导致中间人攻击。比如,本来想下载一个nacos-client的,结果下载的结果中被插入了恶意代码,然后开发人员运行了一下,黑客就能获得开发人员的计算机控制权了。

Maven 3.8.1+就禁止了所有HTTP协议的Maven仓库。

日常开发中,我们经常会用到公司内部的maven仓库。这些仓库一般都是http协议,Maven 3.8.1禁止了http协议,那么就会导致开头的报错。

解决方案: 添加~/.m2/setttings.xml文件写入以下内容,指定这个mirror不对任何仓库生效即可。

# cat settings.xml 
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
<mirrors>
<mirror>
    <id>maven-default-http-blocker</id>
    <mirrorOf>!*</mirrorOf>
    <url>http://0.0.0.0/</url>
</mirror>
</mirrors>
</settings>

0

评论区