Maven构建报错:无法解析maven-clean-plugin:2.5插件求助
Maven构建报错:maven-clean-plugin:2.5无法解析(Unknown host)
环境信息
mvn -version Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: /opt/apache-maven-3.6.3 Java version: 17.0.5, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-17-openjdk-17.0.5.0.8-2.el8.x86_64 Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "4.18.0-326.el8.x86_64", arch: "amd64", family: "unix"
核心报错
[ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.5: Could not transfer artifact org.apache.maven.plugins:maven-clean-plugin:pom:2.5 from/to central (https://repo.maven.apache.org/maven2): Transfer failed for https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom: Unknown host repo.maven.apache.org: Name or service not known -> [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
调试现状
DEBUG模式下卡在下载步骤:
[INFO] --------------------------------[ pom ]--------------------------------- Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom
已知条件:
- 已配置代理的settings.xml无效
wget可正常下载目标pom文件- 其他依赖包能正常下载
解决思路
- 绕过DNS解析问题:直接在
settings.xml中替换central仓库的域名IP(可通过nslookup repo.maven.apache.org获取有效IP),比如将仓库URL改为https://151.101.184.215/maven2,避免Maven的DNS解析异常。 - 强制清理本地缓存:执行
mvn clean install -U,-U参数强制Maven更新依赖缓存,清除本地仓库中可能损坏的maven-clean-plugin相关文件。 - 指定生效的settings文件:命令行明确指定使用的配置文件,避免加载错误的settings:
mvn clean install -s /path/to/your/settings.xml,同时检查代理配置的active="true"是否正确设置。 - 手动安装插件到本地仓库:利用已下载的pom和jar文件,通过Maven命令手动安装:
# 安装pom文件 mvn install:install-file -Dfile=/path/to/maven-clean-plugin-2.5.pom -DgroupId=org.apache.maven.plugins -DartifactId=maven-clean-plugin -Dversion=2.5 -Dpackaging=pom # 下载对应jar后安装 mvn install:install-file -Dfile=/path/to/maven-clean-plugin-2.5.jar -DgroupId=org.apache.maven.plugins -DartifactId=maven-clean-plugin -Dversion=2.5 -Dpackaging=jar - 升级插件版本:在项目pom.xml中显式指定更高版本的maven-clean-plugin,比如3.2.0,规避旧版本的仓库访问问题:
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-clean-plugin</artifactId> <version>3.2.0</version> </plugin> </plugins> </build> - 修正Java网络配置:Maven依赖Java的网络设置,可在命令行强制指定DNS服务器:
mvn clean install -Djava.net.preferIPv4Stack=true -Ddns.server=8.8.8.8,确保Java使用正常的网络解析规则。
内容的提问来源于stack exchange,提问作者pauldx
相关产品推荐
相关产品推荐

