maven setting.xml file structure learning

Also in the process of being constantly learning, if there is not the right place, a warm welcome to correct me, thanks ~

This article will be updated at any time with the author's understanding.

Maven settings .xml file translation

<?xml version="1.0" encoding="UTF-8"?>
<!--
 | 这个是maven的配置文件,它可以在两种级别生效
 |
 |  1. 用户级别。settting.xml 文件可以给单个用户提供配置,
 |              用户级别配置文件通常位于${user.home}/.m2/settings.xml.
 |              注意:这个位置的配置可以用以下命令覆盖:
 |              -s /path/to/user/settings.xml
 | 
 |  2. 全局级别。setting.xml文件给在同一台机器上的全部用户和项目提供配置(假设使用同样的maven安装)
 |              全局级别配置文件通常位于${maven.conf}/settings.xml.
 |              注意:这个位置的配置可以用以下命令覆盖:
 |              -gs /path/to/global/settings.xml
 | 
 | 此文件中提供了大部分的默认配置,当没有指定setting配置文件时,使用该文件中的默认值。
 | 以使你能够在maven安装后快速开始使用。
 |
 |-->
 <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">
  <!-- localRepository
   | 这个路径指定了maven的本地仓库地址,默认为:${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->
  <!-- interactiveMode
   | Maven是否需要和用户交互以获得输入。
   | 如果设置为false,当有参数需要用户指定时,maven将提供一个合理的默认值,或者基于其他设置。
   | 默认: true
  <interactiveMode>true</interactiveMode>
  -->
  <!-- offline
   | 决定maven是否需要在离线模式下构建(build)
   | 默认: false
  <offline>false</offline>
  -->
  <!-- pluginGroups
   | 默认情况下,当运行"mvn prefix:goal"时,maven只会在"org.apache.maven.plugins"和"org.codehaus.mojo"下搜索插件。
   | 当有自定义插件时,可以将包名定义在此,增加搜索范围
   |-->
  <pluginGroups>
    <!-- pluginGroup
     | 指定包名使其能搜索相应插件
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
  </pluginGroups>
  <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
  <proxies>
    <!-- proxy
     | 指定网络代理
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    -->
  </proxies>
  <!-- servers
   | 用户授权管理列表,当链接maven私服时,从这里读取授权信息。
   | 用id标记一个私服
   | 提示: username/password 或者 privateKey/passphrase 需要成对出现
   |-->
  <servers>
    <!-- server
     | 为指定的私服配置权限信息,用id这个属性确定一个唯一的系统
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->
    <!-- 也可以使用key的方式验证信息
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
  <!-- mirrors
   | 这个列表用来配置私服的镜像站点,
   | 主要用来解决从中央仓库或者私服下载网速慢,服务器网络波动等问题。
   | 镜像需要有一个唯一的id,和profile.repository.id相照应。
   | mirrorOf标签用来指定是哪个仓库的镜像源,和profile.repository.id属性相对应。
   | 中央仓库的profile.repository.id默认值是central
   |-->
  <mirrors>
    <!-- mirror
     | id 值必须是唯一的
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
  </mirrors>
  <!-- profiles
   | 根据环境参数来调整构建配置的列表。settings.xml中的profile元素是pom.xml中profile元素的裁剪版本。
   | 它包含了id,activation, repositories, pluginRepositories和 properties元素。
   | 这里的profile元素只包含这五个子元素是因为这里只关心构建系统这个整体(这正是settings.xml文件的角色定位),而非单独的项目对象模型设置。
   | 如果一个settings中的profile被激活,它的值会覆盖任何其它定义在POM中或者profile.xml中的带有相同id的profile。
   |
   | 举个例子,当你在不同的JDK版本下有不同的需求时,你可以设置不同的profile
   |-->
  <profiles>
    <profile>
      <id>jdk-1.4</id>
      <activation>
        <jdk>1.4</jdk>
      </activation>
      <repositories>
        <repository>
          <id>jdk14</id>
          <name>Repository for JDK 1.4 builds</name>
          <url>http://www.myhost.com/maven/jdk14</url>
          <layout>default</layout>
          <snapshotPolicy>always</snapshotPolicy>
        </repository>
      </repositories>
    </profile>
    <!--
     | Here is another profile, activated by the system property 'target-env' with a value of 'dev',
     | which provides a specific path to the Tomcat instance. To use this, your plugin configuration
     | might hypothetically look like:
     |
     | ...
     | <plugin>
     |   <groupId>org.myco.myplugins</groupId>
     |   <artifactId>myplugin</artifactId>
     |
     |   <configuration>
     |     <tomcatLocation>${tomcatPath}</tomcatLocation>
     |   </configuration>
     | </plugin>
     | ...
     |
     | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
     |       anything, you could just leave off the <value/> inside the activation-property.
     |
    <profile>
      <id>env-dev</id>
      <activation>
        <property>
          <name>target-env</name>
          <value>dev</value>
        </property>
      </activation>
      <properties>
        <tomcatPath>/path/to/tomcat/instance</tomcatPath>
      </properties>
    </profile>
    -->
  </profiles>
  <!-- activeProfiles
   | List of profiles that are active for all builds.
   |
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->
</settings>

The relationship between maven setting.xml file inside label instructions

Maven configuration in the relationship between repositories, mirrors, servers

  • repositories in use to specify the remote repository, including remote warehouse uniquely identify, address, name, how to use (such as whether you can pull SnapShot dependent), where you can specify the number of multi-warehouse, maven to find the dependence of the time, if there is no local repository , looking down at it from the remote repository, find downloaded, all looking finish can not find not find a
  • mirrors in designated warehouse agent, by mirrorOf was designated to be the agent of the warehouse (can be specified directly, you can also use some matching characters to specify) to initiating the proxy request to a remote repository, if the repositories in the repository id is mirrorOf matched, then maven repository to send this request was to rule other agent mirrors the URL
  • servers in a given identity authentication information, because most private servers have a user name and password, otherwise unsafe, so look a here specified user name and password, repository where id matches to servers in the id to find the username and password to access the repository

appendix

maven commonly used in the mirror

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

Quote

Maven configuration in the relationship between repositories, mirrors, servers

Guess you like

Origin www.cnblogs.com/virde/p/maven_setting_study.html