maven的setting配置问题

maven的setting配置问题
最近在学习maven的settings.xml配置时遇到了一些不理解的问题
  1. 仓库的搜索优先级。所了解到的是 本地仓库 -> 私服仓库 -> 线上的中央仓库,实际尝试的过程中,我将mirrors镜像注释掉,在profile中配置了几个阿里云仓库,实际下载的时候发现还是走的repo.maven.apache.org/maven2,也就是中央仓库,为什么没有先从私服中查找?

  2. 中央仓库的覆盖。相关博客说,仓库的<id>central</id> 就会覆盖默认的中央仓库,如上所述,可知并没有被覆盖。
    这两个问题我尝试了好多次都没有弄明白,另外假如中央仓库可以覆盖的话,直接覆盖不就好了,何必还要配置镜像呢?求解惑! 具体配置文件如下

    <?xml version="1.0" encoding="UTF-8"?>
    <settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd">
    <localRepository>F:/MavenRepository</localRepository>
    <pluginGroups>
    </pluginGroups>
    <proxies>
    </proxies>
    <servers>
    </servers>
    <mirrors>
     <!-- <mirror>
       <id>nexus-aliyun</id>
       <mirrorOf>central</mirrorOf>
       <name>Nexus aliyun</name>
       <url>http://maven.aliyun.com/nexus/content/groups/public</url>
     </mirror>
      -->    
    </mirrors>
    <profiles>
    <profile>
         <id>aLiCentral</id>
         <repositories>
           <repository>
             <id>central</id>
           <url>http://maven.aliyun.com/nexus/content/groups/public</url>
             <!-- <url>https://maven.aliyun.com/repository/central</url> -->
             <releases>
               <enabled>true</enabled>
             </releases>
             <snapshots>
               <enabled>true</enabled>
               <updatePolicy>always</updatePolicy>
             </snapshots>
           </repository>
         </repositories>
       </profile>
       <profile>
         <id>spring</id>
         <repositories>
           <repository>
             <id>spring</id>
             <url>https://maven.aliyun.com/repository/spring</url>
             <releases>
               <enabled>true</enabled>
             </releases>
             <snapshots>
               <enabled>true</enabled>
               <updatePolicy>always</updatePolicy>
             </snapshots>
           </repository>
         </repositories>
       </profile>
       <profile>
         <id>spring-plugin</id>
         <repositories>
           <repository>
             <id>spring-plugin</id>
             <url>https://maven.aliyun.com/repository/spring-plugin</url>
             <releases>
               <enabled>true</enabled>
             </releases>
             <snapshots>
               <enabled>true</enabled>
               <updatePolicy>always</updatePolicy>
             </snapshots>
           </repository>
         </repositories>
       </profile>
    
     <profile>
         <id>jdk-1.8</id>    
         <activation>    
           <activeByDefault>true</activeByDefault>    
           <jdk>1.8</jdk>    
         </activation>    
         <properties>    
             <maven.compiler.source>1.8</maven.compiler.source>    
             <maven.compiler.target>1.8</maven.compiler.target>    
             <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>    
         </properties> 
     </profile>        
    </profiles> 
    <activeProfiles>
    <activeProfile>aLiCentral</activeProfile>
    <activeProfile>spring</activeProfile>
    <activeProfile>spring-plugin</activeProfile>
    </activeProfiles>
    </settings>
    

可能是以下原因导致的:

1.阿里云仓库未及时同步中央仓库
由于 Maven 中央仓库是所有 Maven 项目都能够访问和使用的公共仓库,因此它的更新速度比较快。而像阿里云这样的私服仓库,需要与中央仓库同步才能保证最新版本的依赖库被下载。因此,如果您的 profile 中的阿里云仓库还没有及时同步最新的中央仓库,就可能无法找到最新的依赖。

2.依赖库已在本地缓存中
Maven 会将您已经下载的依赖库缓存在本地仓库中,以避免每次都重新下载相同的依赖。如果您曾经使用中央仓库下载过某个依赖库,那么该库就会被缓存到本地仓库中。因此,即使您现在使用阿里云仓库,Maven 也会优先从本地缓存中查找依赖库文件。如果本地缓存中已经存在最新版本的依赖库,那么就不需要再从阿里云仓库下载了。

3.没有启用 profile
在 Maven 中,只有在 pom.xml 或 settings.xml 文件中显式地声明了 profile,才会启用该 profile 配置的仓库。因此,在执行 Maven 命令时,请确保已经正确指定了要使用的 profile。您可以使用以下命令来指定 profile:

mvn -P profile-name command

其中,profile-name 是指要使用的 profile 名称,command 是指要执行的 Maven 命令。

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^