The difference between mirror and repository in Maven configuration file and central warehouse configuration

1. The difference between mirror and repository in Maven configuration file

1.1 repository

A repository is a warehouse. There are two kinds of warehouses in maven: local repository and remote repository.

1.1.1 there are three kinds of remote repositories
  • Central warehouse: http://repo1.maven.org/maven2/
  • Private service: maven repository built by intranet itself, whose URL is an internal URL
  • Other public warehouses: others can access maven repository on the Internet, such as jboss repository, etc.
1.1.2 difference between local and remote
  • The remote warehouse is equivalent to a public warehouse, which can be seen by everyone.
  • The local warehouse is your local cache copy. Only you can see it. It is mainly used for caching.
  • When you request plug-ins or dependencies from the warehouse, you will first check whether there are any in the local warehouse. If any, it will be returned directly, otherwise it will be requested from the remote warehouse and cached to the local warehouse.
  • The remote warehouse can be specified in the pom.xml file of the project. If not specified, default to http://repo1.maven.org/maven2 This place to request plug-ins and dependency packages
    <repository>  
          <snapshots>  
              <enabled>false</enabled>  
          </snapshots>  
          <id>central</id>  
          <name>Maven Repository Switchboard</name>  
          <url>http://repo1.maven.org/maven2</url>  
    </repository>  

The local warehouse is in the. m2/repository directory of your local user directory by default

1.2 mirror

Mirror is equivalent to an interceptor. It intercepts maven's requests for remote repository, redirects the remote repository address in the request to the address configured in mirror.
Mirror is a mirror, which mainly provides a convenient way to switch the remote warehouse address. For example, when working in the company, using the telecommunication network, connected to the telecommunication warehouse. When I get home, it's Netcom's network. I want to connect with Netcom's warehouse. I can change the warehouse address of my project into Unicom through mirror configuration, instead of changing the address one by one in the specific project configuration file.
The configuration of mirror is in. m2/settings.xml. Such as:

<mirrors>  
  <mirror>  
    <id>UK</id>  
    <name>UK Central</name>  
    <url>http://uk.maven.org/maven2</url>  
    <mirrorOf>central</mirrorOf>  
  </mirror>  
</mirrors> 

In this way, the remote warehouse with the id of central above will be mirrored. In the future, all requests to the central warehouse will be sent to http://uk.maven.org/maven2 Instead of http://repo1.maven.org/maven2 Now. In < mirrorof > Central < / mirrorof > is the id of the warehouse to be replaced. If you fill in *, it will replace all warehouses.

1.3 advanced image configuration
  1. <mirrorOf>*</mirrorOf>
    Match all remote warehouses.
  2. <mirrorOf>external:*</mirrorOf>
    Match all remote repositories except for localhost and file: / /. That is, match all remote repositories that are not on the local machine.
  3. <mirrorOf>repo1,repo2</mirrorOf>
    Match repositories repo1 and repo2, using commas to separate multiple remote repositories.
  4. <mirrorOf>*,!repo1</mirrorOf>
    Match all remote warehouses except repo1, using exclamation marks to exclude the warehouse from the match.

2. maven central warehouse set

Can be converted into mirror by itself

1. Ali central warehouse
<repository>  
    <id>alimaven</id>
    <name>aliyun maven</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</repository> 
2.camunda.com central warehouse
<repository>  
    <id>activiti-repos2</id>  
    <name>Activiti Repository 2</name>  
    <url>https://app.camunda.com/nexus/content/groups/public</url>  
</repository>  
3.alfresco.com central warehouse
<repository>  
    <id>activiti-repos</id>  
    <name>Activiti Repository</name>  
    <url>https://maven.alfresco.com/nexus/content/groups/public</url>  
</repository>  
4.spring.io central warehouse
<repository>  
    <id>springsource-repos</id>  
    <name>SpringSource Repository</name>  
    <url>http://repo.spring.io/release/</url>  
</repository>
5.maven.apache.org central warehouse
<repository>  
    <id>central-repos</id>  
    <name>Central Repository</name>  
    <url>http://repo.maven.apache.org/maven2</url>  
</repository>
6.maven.org central warehouse
<repository>  
    <id>central-repos1</id>  
    <name>Central Repository 2</name>  
    <url>http://repo1.maven.org/maven2/</url>  
</repository>
7.oschina central warehouse
<repository>  
    <id>oschina-repos</id>  
    <name>Oschina Releases</name>  
    <url>http://maven.oschina.net/content/groups/public</url>  
</repository>  
8.oschina thinkgem central warehouse
<repository>   
    <id>thinkgem-repos</id>   
    <name>ThinkGem Repository</name>  
    <url>http://git.oschina.net/thinkgem/repos/raw/master</url>  
</repository> 
9.java.net central warehouse
<repository>  
    <id>java-repos</id>  
    <name>Java Repository</name>  
    <url>http://download.java.net/maven/2/</url>  
</repository>
10.github.com central warehouse
<repository>   
    <id>thinkgem-repos2</id>   
    <name>ThinkGem Repository 2</name>  
    <url>https://raw.github.com/thinkgem/repository/master</url>  
</repository>  

The first six can be used normally, and the last four may need some magical operations if they are to be used. I won't say that in this case

Reference resources:

Tags: Maven Java nexus xml

Posted on Mon, 30 Mar 2020 09:10:07 -0400 by verN