mvn help:system 需要下载maven-clean-plugin或其他插件 但是连接不了远程仓库导致报错

问题描述

因为需要,想在机器A上搭建maven环境,由于机器A不能接入互联网,所以想把机器B上已有的仓库直接拷贝到A中使用。于是将机器B的整个repository压缩然后复制到机器A中,具体路径C:\.m2\repository。(机器B中可以正确的执行所有mvn命令,因为仓库很全)
然后给机器A中安装JDK、apache-maven-3.6.0,配置相关的环境变量,修改settings.xml中的本地仓库路径。
以上步骤完毕后,执行mvn -v 命令得到如下结果,说明maven安装没有问题。

C:\>mvn -v 
Maven home: D:\software\Apache\apache-maven-3.6.0\bin\..
Java version: 1.8.0_171, vendor: Oracle Corporation, runtime: D:\software\JDK\jdk1.8.0_171\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

此时,执行mvn help:system得到如下结果

C:\>mvn help:system
INFO] Scanning for projects...
Downloading from mirrorId: http://mvnrepository.com/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom
[WARNING] The POM for org.apache.maven.plugins:maven-clean-plugin:jar:2.5 is missing, no dependency information available
Downloading from mirrorId: http://mvnrepository.com/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.jar
·
·太长了,省略一部分。。。
·
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-release-plugin:2.5.3: Plugin org.apache.maven.plugins:maven-release-plugin:2.5.3 or one of its dependencies could not be resolved: Could not find artifact org.apache.maven.plugins:maven-release-plugin:jar:2.5.3 in mirrorId (http://mvnrepository.com/)
Downloading from mirrorId: http://mvnrepository.com/org/apache/maven/plugins/maven-metadata.xml
Downloading from mirrorId: http://mvnrepository.com/org/codehaus/mojo/maven-metadata.xml
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.293 s
[INFO] Finished at: 2018-07-17T18:28:05+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 (C:\.m2\repository), mirrorId (http://mvnrepository.com/)] -> [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] 

解决过程

使用mvn -X -e help:system 获取详细日志,发现有提示找不到maven-metadata.xml,在仓库中搜索后发现有的是maven-metadata-alimaven.xml。
于是想到是不是与settings.xml中的mirrors配置有关,于是增加如下配置:

  <mirrors>
    <mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>        
    </mirror>
  </mirrors>

此处的id配置与maven-metadata-alimaven.xml中的alimaven部分保持一致。

然后重新运行mvn help:system,问题得到了解决。

总结

机器B中的远程仓库,来源于aliyun仓库,所以本地的metadata文件也与之相关,在机器A中如果不配置则会找默认的文件,找不到就导致了需要重新下载相关的内容。

你可能感兴趣的:(maven)