Configuring Maven's Alibaba Cloud Image Warehouse on Mac System

To configure Maven to use the image warehouse provided by Alibaba Cloud, you need to edit the Maven configuration file settings.xml and add the following content:

<mirrors> 
  <mirror>
    <id>aliyunmaven</id> 
    <mirrorOf>*</mirrorOf> 
    <name>阿里云公共仓库</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public 
     </url>
  </mirror>
</mirrors> 

Specific steps are as follows:

  1. Open a terminal and go to the Maven installation directory. By default, this directory is located at /usr/local/apache-maven-, where is the Maven version number.
cp conf/settings.xml conf/settings.xml.backup
  1. Execute the following command to backup Maven's default configuration file:
cp conf/settings.xml conf/settings.xml.backup
  1. Execute the following command to open the settings.xml file using a text editor:
nano conf/settings.xml

If you wish to use a different text editor, replace nano with the name of the desired editor.

  1. Find the tag in the settings.xml file. If it doesn't exist, add the following to the tag:
<mirrors> <!-- Add this mirror configuration --> </mirrors>
  1. Add the following content within the tag:
<mirror> 
  <id>aliyunmaven</id>
  <mirrorOf>central</mirrorOf> 
  <name>阿里云公共仓库</name>
  <url>http://maven.aliyun.com/nexus/content/groups/public
  </url> 
</mirror>

This will create an image named aliyunmaven and set it to match all repositories (*). The name in the tag is optional and is used only for the purpose of describing this image.

  1. Save and close the settings.xml file.
    Now, Maven will use Alibaba Cloud's mirror warehouse to obtain dependencies and plug-ins instead of obtaining them from the default central warehouse. If you want to revert to default settings, use the following command to restore the backed up settings.xml file to its original location:
cp conf/settings.xml.backup conf/settings.xml

Note that if you use the -s or –settings option to specify a customized settings.xml file when executing the mvn command, you need to modify this file instead of Maven's default configuration file.

おすすめ

転載: blog.csdn.net/weixin_56433857/article/details/129854956