1.进入解压目录

2. 编译
mvn clean package -Dmaven.test.skip=true


加载运行环境


BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 06:04 min
[INFO] Finished at: 2025-07-28T16:00:10+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:3.1.0:clean (default-clean) on project java110-boot: Execution default-clean of goal org.apache.maven.plugins:maven-clean-plugin:3.1.0:clean failed: Plugin org.apache.maven.plugins:maven-clean-plugin:3.1.0 or one of its dependencies could not be resolved:
[ERROR] Could not transfer artifact org.codehaus.plexus:plexus-component-annotations:jar:1.7.1 from/to central (https://repo.maven.apache.org/maven2): Connect to repo.maven.apache.org:443 [repo.maven.apache.org/146.75.44.215, repo.maven.apache.org/2a04:4e42:7b:0:0:0:0:215] failed: Network is unreachable (connect failed)
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException
[root@iZ2vcbr09kxsytmlhp8egbZ java110-boot]#
从错误信息来看,Maven 构建失败的核心原因是 无法连接到 Maven 中央仓库(repo.maven.apache.org:443) ,导致 maven-clean-plugin
及其依赖(如 plexus-component-annotations
)无法下载。具体解决方法如下:
一、排查网络连接问题
-
检查服务器网络是否通畅
执行以下命令测试能否访问 Maven 中央仓库:bash
# 测试 DNS 解析 nslookup repo.maven.apache.org # 测试网络连接(能否访问 443 端口) telnet repo.maven.apache.org 443 # 或使用 curl 测试 curl -v https://repo.maven.apache.org/maven2
- 若提示
Network is unreachable
或连接超时,说明服务器网络无法访问外部仓库,需检查:- 服务器是否有网络权限(如阿里云服务器的安全组是否开放出站 443 端口)。
- 是否使用了代理服务器,需配置代理(见下文)。
- 服务器所在网络是否屏蔽了 Maven 中央仓库(如企业内网限制)。
- 若提示
二、配置阿里云 Maven 镜像(推荐)
由于国内访问 Maven 中央仓库可能较慢或不稳定,建议切换为 阿里云镜像(速度更快,无需科学上网):
-
修改 Maven 全局配置文件
找到 Maven 的
settings.xml
文件(路径参考):- 若通过包管理器安装:
/etc/maven/settings.xml
- 若手动安装:
/usr/local/maven/conf/settings.xml
- 若为用户级配置:
~/.m2/settings.xml
(若无则创建)
- 若通过包管理器安装:
-
添加阿里云镜像
在
<mirrors>
标签内添加以下配置:xml
<mirrors> <mirror> <id>aliyunmaven</id> <mirrorOf>*</mirrorOf> <name>阿里云公共仓库</name> <url>https://maven.aliyun.com/repository/public</url> </mirror> <!-- 若需要其他仓库(如 Spring 仓库),可补充 --> <mirror> <id>aliyun-spring</id> <mirrorOf>spring</mirrorOf> <url>https://maven.aliyun.com/repository/spring</url> </mirror> </mirrors>
三、若使用代理服务器,配置 Maven 代理
如果服务器需要通过代理访问外部网络,需在 settings.xml
中配置代理:
xml
<proxies>
<proxy>
<id>proxy</id>
<active>true</active>
<protocol>https</protocol> <!-- 代理协议,http 或 https -->
<host>代理服务器IP或域名</host>
<port>代理端口</port>
<!-- 若代理需要认证 -->
<!-- <username>代理用户名</username> -->
<!-- <password>代理密码</password> -->
<!-- 不需要代理的地址(可选) -->
<!-- <nonProxyHosts>localhost|127.0.0.1</nonProxyHosts> -->
</proxy>
</proxies>
四、清理本地 Maven 仓库缓存
若之前下载过部分依赖但不完整,可能导致缓存冲突,执行以下命令清理:
bash
# 进入本地仓库目录(默认 ~/.m2/repository)
cd ~/.m2/repository
# 删除插件相关的缓存目录(根据错误中的插件路径)
rm -rf org/apache/maven/plugins/maven-clean-plugin/
rm -rf org/codehaus/plexus/plexus-component-annotations/
五、重新构建项目
完成上述配置后,再次执行构建命令:
bash
# 清理并重新构建(加 -U 强制更新依赖)
mvn clean package -U
-U
参数强制 Maven 检查远程仓库的更新,避免使用本地缓存的错误依赖。
六、其他可能的原因
-
Maven 版本兼容问题
若
maven-clean-plugin:3.1.0
持续报错,可尝试在pom.xml
中指定更低版本的插件(如 3.0.0):xml
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-clean-plugin</artifactId> <version>3.0.0</version> </plugin> </plugins> </build>
-
服务器时间同步问题
若服务器时间与实际时间偏差较大,可能导致 SSL 证书验证失败,执行以下命令同步时间:
bash
# 安装时间同步工具 sudo dnf install -y ntpdate # 同步网络时间 sudo ntpdate ntp.aliyun.com
阿雪技术观
在科技发展浪潮中,我们不妨积极投身技术共享。不满足于做受益者,更要主动担当贡献者。无论是分享代码、撰写技术博客,还是参与开源项目维护改进,每一个微小举动都可能蕴含推动技术进步的巨大能量。东方仙盟是汇聚力量的天地,我们携手在此探索硅基生命,为科技进步添砖加瓦。
Hey folks, in this wild tech - driven world, why not dive headfirst into the whole tech - sharing scene? Don't just be the one reaping all the benefits; step up and be a contributor too. Whether you're tossing out your code snippets, hammering out some tech blogs, or getting your hands dirty with maintaining and sprucing up open - source projects, every little thing you do might just end up being a massive force that pushes tech forward. And guess what? The Eastern FairyAlliance is this awesome place where we all come together. We're gonna team up and explore the whole silicon - based life thing, and in the process, we'll be fueling the growth of technology.