Maven公共仓库和私有仓库的问题

问题描述

Non-resolvable parent POM for tech.foolfish:demo:0.0.1: tech.foolfish:foolfish-sdk:pom:1.0.0 was not found in https://maven.aliyun.com/repository/public during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of aliyunmaven has elapsed or updates are forced

解决办法

xuej@xuej-VirtualBox:~$ whereis mvn
mvn: /usr/maven/apache-maven-3.6.0/bin/mvn.cmd /usr/maven/apache-maven-3.6.0/bin/mvn
xuej@xuej-VirtualBox:~$ ll /usr/maven/apache-maven-3.6.0/conf/
total 28
drwxr-xr-x 3  501 staff  4096 10 25 14:35 ./
drwxr-xr-x 6 root root   4096 5   3 23:53 ../
drwxr-xr-x 2  501 staff  4096 10 25  2018 logging/
-rw-r--r-- 1  501 staff 10395 10 25 14:35 settings.xml
-rw-r--r-- 1  501 staff  3645 10 25  2018 toolchains.xml
xuej@xuej-VirtualBox:~$ vim /usr/maven/apache-maven-3.6.0/conf/settings.xml 
<mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
    <mirror>
      <id>aliyunmaven</id>
      <mirrorOf>*</mirrorOf>
      <name>阿里云公共仓库</name>
      <url>https://maven.aliyun.com/repository/public</url>
    </mirror>
</mirrors>
xuej@xuej-VirtualBox:~$ ll .m2/
total 24
drwxrwxr-x  3 xuej xuej  4096 10 25 14:36 ./
drwxr-xr-x 28 xuej xuej  4096 10 26 12:12 ../
drwxrwxr-x 40 xuej xuej  4096 10 25 15:15 repository/
-rw-r--r--  1 xuej xuej 10402 10 25 14:36 settings.xml
xuej@xuej-VirtualBox:~$ vim .m2/settings.xml 
<mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
    <mirror>
      <id>maven-public</id>
      <mirrorOf>*</mirrorOf>
      <name>maven-public</name>
      <url>http://10.***.***.***:8082/nexus/repository/maven-public/</url>
    </mirror>
</mirrors>
xuej@xuej-VirtualBox:~/Documents/foolfish/demo$ mvn clean package -U

小结

  1. 首先需要配置私有仓库
  2. settings.xml的优先级:.m2/settings.xml的优先级高于/usr/maven/apache-maven-3.6.0/conf/settings.xml
  3. 配置完之后,如果pom依然报错,主要是因为Maven默认会使用本地缓存的库来编译工程,而上次下载库的时候失败了