Maven configuration priority (summary)

I. Introduction

When the company's internal research and development projects, some common tools are usually packaged into jar packages and uploaded to their own Maven private servers. These jar packages may only be provided on the company's intranet. When we are not in the company, we may need to download some other jar packages. We can choose Alibaba Cloud as the Maven mirroring proxy address. When switching the Maven configuration file settings.xml, be sure to figure out the validity of the configuration file, otherwise unreasonable configuration may cause some jar packages to fail to download!

Two, settings.xml configuration file priority

Priority: pom.xml> user settings> global settings

Description :

  • Global configuration: ${M2_HOME}/conf/settings.xml (configurable by Eclipse or Idea development tools)
  • User configuration: user.home/.m2/settings.xml (configurable by Eclipse or Idea development tools)
  • Local configuration takes precedence over global configuration
  • If these files exist at the same time, their contents will be merged when the configuration is applied. If there are duplicate configurations, the configuration with the higher priority will overwrite the configuration with the lower priority. (Merge coverage principle)

Three, view the effective configuration

Take the Idea development tool as an example:

1. Select the project=>Right click=>Run Maven=>New Goal...

Run-Maven

2. Enter help:effective-settings, click Run, the console will output the final settings.xml file after merging and overwriting.

3. Enter help: active-profiles, click Run, the console will output the effective profiles; Idea tool Maven window will directly display the effective status of the profiles.

Fourth, Alibaba Cloud mirroring agent settings.xml

Note : It is recommended to put it directly in the ${M2_HOME}/conf directory and overwrite the original settings.xml file as the default global configuration. In the company's internal private warehouse, a settings.xml is set separately and configured in the User settings file input box of Idea as a merged and overwritten configuration.

<?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">
 
    <!-- 默认的值是${user.home}/.m2/repository -->
    <localRepository>D:\maven\aliyun-repository</localRepository>
 
    <!-- 如果Maven要试图与用户交互来得到输入就设置为true,否则就设置为false,默认为true。 -->
    <interactiveMode>true</interactiveMode>
 
    <!-- 如果Maven使用${user.home}/.m2/plugin-registry.xml来管理plugin的版本,就设置为true,默认为false。 -->
    <usePluginRegistry>false</usePluginRegistry>
 
    <!-- 如果构建系统要在离线模式下工作,设置为true,默认为false。 如果构建服务器因为网络故障或者安全问题不能与远程仓库相连,那么这个设置是非常有用的。 -->
    <offline>false</offline>
 
 <mirrors>

    <mirror>
        <id>nexus-aliyun</id>
		<mirrorOf>central,spring-milestone,spring-plugins-release,spring-libs-release,spring-snapshot</mirrorOf>
        <name>Nexus aliyun</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror>   
     
  </mirrors>
 
    <!-- settings.xml中的profile是pom.xml中的profile的简洁形式。 它包含了激活(activation),仓库(repositories),插件仓库(pluginRepositories)和属性(properties)元素。 
        profile元素仅包含这四个元素是因为他们涉及到整个的构建系统,而不是个别的POM配置。 如果settings中的profile被激活,那么它的值将重载POM或者profiles.xml中的任何相等ID的profiles。 -->
    <profiles>
        <profile>
            <id>default</id>
            <activation>
                <activeByDefault>true</activeByDefault>
                <jdk>1.8</jdk>
            </activation>
            <repositories>
                <repository>
                    <id>aliyun-public</id>
                    <name>aliyun public</name>
                    <url>https://maven.aliyun.com/repository/public</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <layout>default</layout>        
                </repository>

                <repository>
                    <id>aliyun-central</id>
                    <name>aliyun central</name>
                    <url>https://maven.aliyun.com/repository/central</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <layout>default</layout>        
                </repository>

                <repository>
                    <id>aliyun-spring</id>
                    <name>aliyun spring</name>
                    <url>https://maven.aliyun.com/repository/spring</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <layout>default</layout>        
                </repository>

                <repository>
                    <id>aliyun-spring-plugin</id>
                    <name>aliyun spring-plugin</name>
                    <url>https://maven.aliyun.com/repository/spring-plugin</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <layout>default</layout>        
                </repository>

                <repository>
                    <id>aliyun-apache-snapshots</id>
                    <name>aliyun apache-snapshots</name>
                    <url>https://maven.aliyun.com/repository/apache-snapshots</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <layout>default</layout>        
                </repository>

                <repository>
                    <id>aliyun-google</id>
                    <name>aliyun google</name>
                    <url>https://maven.aliyun.com/repository/google</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <layout>default</layout>        
                </repository>

                <repository>
                    <id>aliyun-gradle-plugin</id>
                    <name>aliyun gradle-plugin</name>
                    <url>https://maven.aliyun.com/repository/gradle-plugin</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <layout>default</layout>        
                </repository>

                <repository>
                    <id>aliyun-jcenter</id>
                    <name>aliyun jcenter</name>
                    <url>https://maven.aliyun.com/repository/jcenter</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <layout>default</layout>        
                </repository>

                <repository>
                    <id>aliyun-releases</id>
                    <name>aliyun releases</name>
                    <url>https://maven.aliyun.com/repository/releases</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <layout>default</layout>        
                </repository>

                <repository>
                    <id>aliyun-snapshots</id>
                    <name>aliyun snapshots</name>
                    <url>https://maven.aliyun.com/repository/snapshots</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <layout>default</layout>        
                </repository>

                <repository>
                    <id>aliyun-grails-core</id>
                    <name>aliyun grails-core</name>
                    <url>https://maven.aliyun.com/repository/grails-core</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <layout>default</layout>        
                </repository>

                <repository>
                    <id>aliyun-mapr-public</id>
                    <name>aliyun mapr-public</name>
                    <url>https://maven.aliyun.com/repository/mapr-public</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <layout>default</layout>        
                </repository>
                <repository>
                    <id>spring-milestone</id>
                    <name>Spring Milestone Repository</name>
                    <url>https://repo.spring.io/milestone</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <layout>default</layout>
                </repository>
                <repository>
                    <id>spring-plugins-release</id>
                    <name>Spring plugins Repository</name>
                    <url>https://repo.spring.io/plugins-release/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <layout>default</layout>
                </repository>
                <repository>
                    <id>spring-libs-release</id>
                    <name>Spring libs Repository</name>
                    <url>https://repo.spring.io/libs-release/</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>https://repo.spring.io/snapshot</url>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                    <layout>default</layout>
                </repository>
            </repositories>
        </profile>
    </profiles>
    <!-- activations是profile的关键,就像POM中的profiles,profile的能力在于它在特定情况下可以修改一些值。 
        而这些情况是通过activation来指定的。 -->
    <!-- <activeProfiles/> -->
 
</settings>

Note : All central, especially settings.xml as a global configuration, is not recommended to be set to * to avoid the problem that the configuration content should not be overwritten.

Guess you like

Origin blog.csdn.net/ory001/article/details/108616831