ubuntu\Deepin等 Linux下 Maven 无法下载依赖

74 阅读4分钟

  今天的 Java 的 Maven 环境完完整整地耗了我一整天的时间,真的是恶心死人!!!

  事情的起因还得是我把操作系统从 Windows 换成了 Linux(Deepin,Ubuntu 也一样,内核都是 debain),装上 Idea 、Maven镜像配置之后,打开工程,无论如何就是下载不了依赖;必应一通,网上的解决方案千篇一律,没一个好使的!!不过还好已经解决了!下面我就把整个解决过程分享给大家,希望能有用!!

问题现象描述

idea 现象

image.png Plugins 下面直接缺 Maven 最基础的 clean\install\site\deploy 插件。为此尝试过:1)删除工程的.idea目录,并清理掉 Idea 的缓存并重启 Idea,重新打开工程加载 Maven;2)给 Idean 的 Maven-- Importing、runner 中添加过允许 jre 或者忽略 jre 证书的方法;3)怀疑是 Idea 版本问题重新下载 Idea 的方法,最终上述方法都没解决问题。

纯Maven 现象

  由于怀疑 Idea 的 Maven 是不是存在问题,于是我下载的纯净的 Maven。下面是的纯净 Maven 配置好后,在终端运行 mvn help:system 报出的异常信息:

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  27.832 s
[INFO] Finished at: 2025-08-07T20:59:45+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] No plugin found for prefix 'help' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/home/OceanLee/.m2/repository), central (https://repo.maven.apache.org/maven2)] -> [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/NoPluginFoundForPrefixException

中间还是掺杂着如java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty等不知所以然的异常信息(就是因为这个异常,网上的牛人们说要设置什么忽略或者开启 jre 证书的):

Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-dependency-plugin/3.7.0/maven-dependency-plugin-3.7.0.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-dependency-plugin:3.7.0: Plugin org.apache.maven.plugins:maven-dependency-plugin:3.7.0 or one of its dependencies could not be resolved:
    The following artifacts could not be resolved: org.apache.maven.plugins:maven-dependency-plugin:pom:3.7.0 (absent): Could not transfer artifact org.apache.maven.plugins:maven-dependency-plugin:pom:3.7.0 from/to central (https://repo.maven.apache.org/maven2): java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty

Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-release-plugin/3.0.1/maven-release-plugin-3.0.1.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-release-plugin:3.0.1: Plugin org.apache.maven.plugins:maven-release-plugin:3.0.1 or one of its dependencies could not be resolved:
    The following artifacts could not be resolved: org.apache.maven.plugins:maven-release-plugin:pom:3.0.1 (absent): Could not transfer artifact org.apache.maven.plugins:maven-release-plugin:pom:3.0.1 from/to central (https://repo.maven.apache.org/maven2): java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty

总之就是一句话就是依赖死活下载不下来,无论你是使用 Idea 自带的 Maven,还是从 Apache 重新下载 JDK1.8、JDK1.7的 Maven ,哪怕是你把本地的 repository 日录整个清理全部删除都无济于事,就是报错。我甚至都怀疑我的 JDK 是不是没装对,还重新下载了一版 JDK……搞到最后我都决定要用 Gradle 了,但是还是坚持了下!

解决方法

  问题的最终原因还是因为settings.xml 中镜像的问题,注意,不是镜像没有配置对,是镜像本身的问题或者操作系统网络的问题(因为同样的镜像地址在 Mac、Windows 下都能正常下载依赖,但是我换了其它源地址后也能正常下载,所以是镜像本身的问题可能性最大),这里我也只讨论镜像本身,操作系统网络因为时间问题没有专门去试。

具体操作

  把Maven Settings.xml 文件的中的 Mirror 从淘宝源、Maven的默认中央仓库等一系列下载失败的源换成腾讯云的源即可,就这么简单!!!(你们说说多耽误事儿……淦)下面是腾讯的镜像配置:

    <mirror>  
        <id>nexus-tencentyun</id>  
        <mirrorOf>*</mirrorOf>  
        <name>Nexus tencentyun</name>  
        <url>http://mirrors.cloud.tencent.com/nexus/repository/maven-public/</url>  
    </mirror>

配置完成后,需要把本机上的Maven repository 全部清理掉(或者把所有以 lastupdate 结尾的文件全删除),重新打开工程重新下载依赖(中途同样会有个别依赖下载失败,但是只要把它的 lastupdate 文件删除重新下载就会成功)。

  中途其实我还尝试了华为的、网易的源都不行,其中网易的源能下载下来了 pom 文件、xml 文件等,但是就是没有 jar 文件,所以就没多等直接换下个源了。其它源都是下载来一个 lastupdate 文件,无语。

(这是我在网上抄的 Maven 镜像源汇总地址:wiki.zjq.im/docs/java/c…