使用代理上网, 新建的 maven 项目中, 在本地仓库中的settings.xml配置阿里云镜像, 但是下载插件报错, 具体报错详情如下
报错详情
Caused by: java.lang.RuntimeException: org.apache.maven.wagon.TransferFailedException: Connect to maven.aliyun.com:80 [maven.aliyun.com/59.110.251.12, maven.aliyun.com/182.92.29.40, maven.aliyun.com/182.92.29.16, maven.aliyun.com/182.92.29.53, maven.aliyun.com/59.110.251.9, maven.aliyun.com/59.110.251.4, maven.aliyun.com/182.92.29.54, maven.aliyun.com/59.110.251.10, maven.aliyun.com/182.92.29.13, maven.aliyun.com/59.110.251.11] failed: Connection timed out: connect
报错原因
经常分析查找, 发现是没有给 maven 设置代理, 导致下载失败
解决办法
- 找到当前项目 maven 安装目录conf中的 settings.xml, 配置代理
如我的maven 安装目录, D:/software/maven/apache-maven-3.6.0/conf/settings.xml
在settings.xml 文件中添加代理
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<host>172.16.100.211</host>
<port>808</port>
</proxy>
- 删除本地 localReposity (D:\software\maven\apache-maven-3.6.0\localReposity) 中的文件,重新导入所有maven项目(reimport all maven projects)
setting.xml 完整文件
<?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
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
<!--本地存储库mavne 的路径,用于存储构建-->
<localRepository>D:\software\maven\apache-maven-3.6.0\localReposity</localRepository>
<pluginGroups>
<!-- pluginGroup
| Specifies a further group identifier to use for plugin lookup.
<pluginGroup>com.your.plugins</pluginGroup>
-->
</pluginGroups>
<proxies>
<!-- proxy
| Specification for one proxy, to be used in connecting to the network.
| 指定一个代理,用于连接到网络。
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>proxyuser</username>
<password>proxypass</password>
<host>proxy.host.net</host>
<port>80</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
-->
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<host>172.16.100.211</host> <!--代理地址-->
<port>808</port> <!--代理端口-->
</proxy>
</proxies>
<!-- servers
| This is a list of authentication profiles, keyed by the server-id used within the system.
| Authentication profiles can be used whenever maven must make a connection to a remote server.
|-->
<servers>
<!-- server
| Specifies the authentication information to use when connecting to a particular server, identified by
| a unique name within the system (referred to by the 'id' attribute below).
|
| NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
| used together.
|
<server>
<id>deploymentRepo</id>
<username>repouser</username>
<password>repopwd</password>
</server>
-->
<!-- Another sample, using keys to authenticate.
<server>
<id>siteServer</id>
<privateKey>/path/to/private/key</privateKey>
<passphrase>optional; leave empty if not used.</passphrase>
</server>
-->
</servers>
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<!--配置国内阿里云镜像-->
<mirror>
<id>nexus-aliyun</id>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>jdk-1.8</id>
<activation>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
</profiles>
<!-- activeProfiles
| List of profiles that are active for all builds.
|
<activeProfiles>
<activeProfile>alwaysActiveProfile</activeProfile>
<activeProfile>anotherAlwaysActiveProfile</activeProfile>
</activeProfiles>
-->
</settings>