有时构建工程,会出现下面这种格式的报错
Could not transfer artifact com.alibaba.cloud:aliyun-spring-boot-dependencies:pom:1.0.0 from/to central (https://repo.maven.apache.org/maven2): Connect to repo.maven.apache.org:443 [repo.maven.apache.org/151.101.76.215] failed: connect timed out
步骤:单独提取国内镜像加速配置
1. Maven 仓库镜像加速配置
将以下部分提取出来,添加到你的 settings.xml
文件中。settings.xml
文件通常位于 Maven
的配置目录(如 C:\Users\<你的用户名>\.m2\...\settings.xml
)下:
<mirrors>
<mirror>
<id>aliyun-central</id>
<mirrorOf>central</mirrorOf>
<url>https://maven.aliyun.com/repository/central</url>
</mirror>
<mirror>
<id>aliyun-spring</id>
<mirrorOf>spring</mirrorOf>
<url>https://maven.aliyun.com/repository/spring</url>
</mirror>
</mirrors>
2. 添加国内镜像的仓库配置
在项目下 pom.xml
文件中单独指定 Maven 仓库(如阿里云仓库):
复制下来粘到这里
代码如下
<repositories>
<repository>
<id>aliyun-central</id>
<url>https://maven.aliyun.com/repository/central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>aliyun-spring</id>
<url>https://maven.aliyun.com/repository/spring</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>aliyun-central</id>
<url>https://maven.aliyun.com/repository/central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
这样做能够确保你的项目无论是在国内还是在其他网络环境下,都能有效地进行依赖下载和构建。