maven setting.xml configuration and explanation

maven download jar rules

  1. When maven downloads the jar package, it will first search for the jar from the configured local repository localRepository. If it cannot find the jar, it will download the jar from the configured remote repository.
  2. The configured remote warehouse has a corresponding ID. You can fill in the ID of the corresponding warehouse according to the tag, which means that when downloading the jar from this warehouse, the corresponding mirror will be used.
  3. If the jar cannot be downloaded, an error will be reported.
  4. The plugin will be downloaded from the configured pluginRepository, same as above

setting.xml configuration explanation

The role of the server tag

When using mvn install, the project packages will be installed into the local maven repository.
When using mvn deploye, the project package will be deployed to the remote maven warehouse, so that anyone with permission to access the remote warehouse can access your jar package
Inform maven of the remote warehouse address deployed by using the distributionManagement tag in ***pom.xml***. The example is as follows
Since some remote warehouses have password permissions, if it is not configured in in setting.xml, a 401 error will be reported. The ID of the label must be consistent with the ID of the warehouse in distributionManagement. For details, see the code below.

<distributionManagement>
<!-- Official warehouse -->
<repository>
<id>releases</id>
<name>releases</name>
<url>http://nexus.xinfangsheng.info:8081/repository/maven-releases/</url>
</repository>
<!-- Snapshot warehouse -->
<snapshotRepository>
<id>snapshot</id>
<name>snapshot</name>
<url>http://nexus.xinfangsheng.info:8081/repository/maven-snapshots/</url>
    </snapshotRepository>
</distributionManagement>

 <?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

   <!-- The default value is ${user.home}/.m2/repository -->
   <localRepository>E:\apache\repository</localRepository>

   <!-- Set to true if Maven is trying to interact with the user to get input, otherwise set to false. The default is true. -->
   <interactiveMode>true</interactiveMode>

   <!-- If Maven uses ${user.home}/.m2/plugin-registry.xml to manage plugin versions, set it to true, and the default is false. -->
   <usePluginRegistry>false</usePluginRegistry>

   <!-- Set to true if the build system is to work in offline mode, default is false. This setting is useful if the build server cannot connect to the remote repository due to network failure or security issues. -->
   <offline>false</offline>

   <servers>
       <!-- server
        | Specifies the authentication information to use when connecting to a particular server, identified by
        | a unique name within the system (referred to by the 'id' attribute below).
        |
        | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
        | used together.
        |
       -->
       <!-- The function of the server tag is as follows -->
       <!-- When using mvn install, the project package will be installed into the local maven repository -->
       <!-- When using mvn deploye, the project package will be deployed to the remote maven warehouse, so that anyone with permission to access the remote warehouse can access your jar package -->
       <!-- Inform maven of the remote warehouse address deployed by using the distributionManagement tag in pom.xml, -->

       <server>
           <id>snapshot</id>
           <username>developer</username>
           <password>*******</password>
           <filePermissions>664</filePermissions>
           <directoryPermissions>775</directoryPermissions>
       </server>
        <server>
           <id>releases</id>
           <username>developer</username>
           <password>***********</password>
           <filePermissions>664</filePermissions>
           <directoryPermissions>775</directoryPermissions>
       </server>
   </servers>

   <mirrors>
       <mirror>
           <id>aliyunmaven</id>
           <mirrorOf>*</mirrorOf><!--* means that all jar packages are downloaded from Alibaba Cloud-->
           <!--<mirrorOf>central</mirrorOf>--><!--central means that only jar packages from the central warehouse can be downloaded from Alibaba Cloud-->
           <!-- maven will have a central warehouse with a default id of "central" -->
         <name>Alibaba Cloud Public Warehouse</name>
           <url>https://maven.aliyun.com/repository/public</url>
       </mirror>

       <!--Old version of Alibaba Cloud public warehouse-->
       <!--
       <mirror>
           <id>nexus-aliyun</id>
           <mirrorOf>central</mirrorOf>
           <name>Nexus aliyun</name>
           <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
       </mirror>
       -->
       
       <!-- Mirror of the central warehouse in China -->
       <mirror>
           <id>maven.net.cn</id>
           <name>Mirror from Maven in china</name>
           <url>http://maven.net.cn/content/groups/public/</url>
           <mirrorOf>central</mirrorOf>
       </mirror>
   </mirrors>




   <!-- The profile in settings.xml is a concise form of the profile in pom.xml. It contains activation, repositories, pluginRepositories and properties elements.
       The profile element only contains these four elements because they relate to the entire build system, not individual POM configurations. If a profile in settings is activated, then its value will override any profiles with an equal ID in the POM or profiles.xml. -->
    <!-- If the repository is configured in the setting, it is equivalent to the configuration in the project's pom -->
   <profiles>
       <profile>
         <!-- Specify the id of the profile -->
           <id>dev</id>
           <!-- Remote warehouse-->
           <repositories>
               <!-- Alibaba Cloud Remote Warehouse-->
               <repository>
                   <id>aliyun</id>
                   <name>aliyun maven Repository</name>
                   <url>https://maven.aliyun.com/repository/public</url>
                 <!-- Only download the release version from this repository -->
                   <releases>
                       <enabled>true</enabled>
                   </releases>
                   <snapshots>
                       <enabled>false</enabled>
                   </snapshots>
               </repository>
               <repository>
                   <id>spring-milestone</id>
                   <name>Spring Milestone Repository</name>
                   <url>http://repo.spring.io/milestone</url>
                   <releases>
                       <enabled>true</enabled>
                   </releases>
                   <snapshots>
                       <enabled>false</enabled>
                   </snapshots>
                   <layout>default</layout>
               </repository>
               <repository>
                   <id>spring-snapshot</id>
                   <name>Spring Snapshot Repository</name>
                   <url>http://repo.spring.io/snapshot</url>
                   <releases>
                       <enabled>false</enabled>
                   </releases>
                   <snapshots>
                       <enabled>true</enabled>
                   </snapshots>
                   <layout>default</layout>
               </repository>
           </repositories>
           <!-- Mirror, if added, it will be downloaded from the Alibaba Cloud warehouse first -->
           <pluginRepositories>
             <!-- Plug-in repository. Plug-ins are downloaded from these repositories -->
               <pluginRepository>
                   <id>aliyun-plugin</id>
                   <url>https://maven.aliyun.com/repository/public</url>
                   <releases>
                       <enabled>true</enabled>
                   </releases>
                   <snapshots>
                       <enabled>false</enabled>
                   </snapshots>
               </pluginRepository>
           </pluginRepositories>
       </profile>
   </profiles>
   <!-- Activations are the key to profile, just like profiles in POM. The ability of profile is that it can modify some values under specific circumstances.
       These situations are specified through activation. -->
   <!-- <activeProfiles/> -->
 <activeProfiles>
   <activeProfile>dev</activeProfile>
 </activeProfiles>
</settings>