maven Replacement Central Warehouse - Aliyun

Keywords: Programming Maven Spring xml nexus

The connection speed is too slow when visiting Maven warehouse in China. The following is how to replace the central warehouse with the central warehouse in Aliyun.

First, uniform modification of warehouse address

You can directly modify the set. xml file in the Mavenconf folder, or create a set. xml file in the. m2 folder.

There is a mirrors node in set. XML to configure the mirror URL. Mirrors can be configured with multiple mirrors, each mirror has id,name,url,mirrorOf attributes.

  • id is the only one that identifies a mirror
  • name doesn't seem to be very useful. It's equivalent to description.
  • url is the official library address
  • Mirror Of represents an alternative location for a mirror, such as central, which replaces the official central repository.

Mirrors are not queried in the same order as they are written in settings.xml. The so-called first is not necessarily the top one.

When mirrors with id B, A and C are in the mirrors node, maven will specify the first one according to the alphabetical order, so no matter how they are arranged, the mirror A will be found for searching. When A is unable to connect, it will go to B only in case of an accident.

Add the following code in set xml:

...
<mirrors>  
    ...   
    <mirror>  
      <id>alimaven</id>  
      <name>aliyun maven</name>  
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>  
      <mirrorOf>central</mirrorOf>          
    </mirror>
</mirrors>

The second is to allocate different central repositories for each project.

Modify the address of the central repository directly in the pom.xml of the project. As follows:

<repositories>
	<repository>
		<id>alimaven</id>
		<name>aliyun maven</name>
		<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
	</repository>
</repositories>

Complete pom:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.xiaolyuh</groupId>
	<artifactId>spring-boot-student</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>pom</packaging>
	<name>spring-boot-student</name>

	<!-- Add to Spring Boot The parent dependency, so the current project is Spring Boot Project. spring-boot-starter-parent It's a special one. starter,He used 
		Provide relevant maven Default dependencies, after using them, common dependencies can be omitted version Label -->
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.5.3.RELEASE</version>
		<relativePath /> <!-- lookup parent from repository -->
	</parent>

	<repositories>
		<repository>
			<id>alimaven</id>
			<name>aliyun maven</name>
			<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
		</repository>
	</repositories>

	<!-- Or in maven Of setting Add to the document -->
	<!--<mirror>
		<id>alimaven</id>
		<name>aliyun maven</name>
		<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
		<mirrorOf>central</mirrorOf>
	</mirror>-->

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

	<modules>
		<module>spring-boot-student-banner</module>
    </modules>

</project>

Posted by dusty on Mon, 07 Oct 2019 11:47:37 -0700