maven configures Alibaba cloud images in two ways

maven configures Alibaba cloud images in two ways

collocation method

The first method (settings.xml file)

Add a new mirror node under the mirrors node and configure the Ali image address. The complete configuration is as follows:

<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 method (pom.xml method)

Modify the project pom.xml, add the repository node under the repositories node, and configure the Ali image address. The complete configuration is as follows:

This configuration refers to the pom.xml configuration of the Ren genertor project. The project website is: https://gitee.com/renrenio/renren-generator

<repositories>
		<repository>
			<id>public</id>
			<name>aliyun nexus</name>
			<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
			<releases>
				<enabled>true</enabled>
			</releases>
		</repository>
	</repositories>
	<pluginRepositories>
		<pluginRepository>
			<id>public</id>
			<name>aliyun nexus</name>
			<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
			<releases>
				<enabled>true</enabled>
			</releases>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</pluginRepository>
	</pluginRepositories>

difference

The first method is global configuration

The second method can only be effective for the current project

Problems solved

Problem Online

Recently, the company has configured a maven private server warehouse, which leads to the need to pull the dependencies required by our project from the private server. The Maven warehouse address configured in my idea is also a private server. In addition, if it is developed through the intranet, your notebook is not only used in the company. If you want to switch the Maven warehouse after learning, it is quite troublesome

Sample test

We will create a new springboot project, define a springboot version that does not exist locally, and package it with a private server warehouse address on the Internet

Reason for error reporting: because we use the Internet, we can't pull it to the private server warehouse

Solution

Adapt to the second method above (pom.xml method)

Configure alicloud images in pom.xml

pom.xml is configured as follows:

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>springboot-demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>springboot-demo</name>
    <description>Demo project for Spring Boot</description>

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

    <dependencies>
       Omit...
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.3.7.RELEASE</version>
                <configuration>
                    <mainClass>com.example.springbootdemo.SpringbootDemoApplication</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <id>repackage</id>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
<repositories>
		<repository>
			<id>public</id>
			<name>aliyun nexus</name>
			<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
			<releases>
				<enabled>true</enabled>
			</releases>
		</repository>
	</repositories>
	<pluginRepositories>
		<pluginRepository>
			<id>public</id>
			<name>aliyun nexus</name>
			<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
			<releases>
				<enabled>true</enabled>
			</releases>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</pluginRepository>
	</pluginRepositories>

</project>

Packaging process:

End of packaging

summary

1. If the working computer company is dual-purpose, we can configure Alibaba cloud images in pom.xml, but each project should be configured

2. If the computer is only for self-learning, we can configure the global alicloud image in settings.xml, once and for all

Personal CSDN blog website: https://blog.csdn.net/shaoming314

Personal blog website: www.shaoming.club

raw/master/image/jam.jpg" alt="jam" style="zoom:33%;" />

Personal blog website: www.shaoming.club

Tags: Java Operation & Maintenance Maven Spring Boot

Posted on Sat, 18 Sep 2021 23:32:01 -0400 by basheer12m