Maven的settings.xml配置詳解


子節點詳細介紹轉載:http://www.cnblogs.com/jingmoxukong/p/6050172.html?utm_source=gold_browser_extension

全局配置

<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<!--
 | This is the configuration file for Maven. It can be specified at two levels:
 |
 |  1. User Level. This settings.xml file provides configuration for a single user,
 |                 and is normally provided in ${user.home}/.m2/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -s /path/to/user/settings.xml
 |
 |  2. Global Level. This settings.xml file provides configuration for all Maven
 |                 users on a machine (assuming they're all using the same Maven
 |                 installation). It's normally provided in
 |                 ${maven.conf}/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -gs /path/to/global/settings.xml
 |
 | The sections in this sample file are intended to give you a running start at
 | getting the most out of your Maven installation. Where appropriate, the default
 | values (values used when the setting is not specified) are provided.
 |
 |-->
<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
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->
  <localRepository>D:/server/MavenRepository/maven_jar</localRepository>

  <!-- interactiveMode
   | This will determine whether maven prompts you when it needs input. If set to false,
   | maven will use a sensible default value, perhaps based on some other setting, for
   | the parameter in question.
   |
   | Default: true
  <interactiveMode>true</interactiveMode>
  -->

  <!-- offline
   | Determines whether maven should attempt to connect to the network when executing a build.
   | This will have an effect on artifact downloads, artifact deployment, and others.
   |
   | Default: false
  <offline>false</offline>
  -->

  <!-- pluginGroups
   | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
   | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
   | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
   |-->
  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <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
     | Specification for one proxy, to be used in connecting to the network.
     |
    <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
   | This is a list of authentication profiles, keyed by the server-id used within the system.
   | Authentication profiles can be used whenever maven must make a connection to a remote server.
   |-->
  <servers>
    <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     |
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
     |       used together.
     |
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->
    
    <server>
      <id>docker-hub</id>
      <username>admin</username>
      <password>Harbor12345</password>
    </server>
     <server>  
        <id>maven-releases</id>  
        <username>admin</username>  
        <password>admin123</password>  
      </server>  
      <server>  
        <id>maven-snapshots</id>  
        <username>admin</username>  
        <password>admin123</password>  
      </server> 
      <server>  
        <id>topcheer</id>  
        <username>admin</username>  
        <password>admin123</password>  
      </server> 

    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
  </servers>

  <!-- mirrors
   | This is a list of mirrors to be used in downloading artifacts from remote repositories.
   |
   | It works like this: a POM may declare a repository to use in resolving certain artifacts.
   | However, this repository may have problems with heavy traffic at times, so people have mirrored
   | it to several places.
   |
   | That repository definition will have a unique id, so we can create a mirror reference for that
   | repository, to be used as an alternate download site. The mirror site will be the preferred
   | server for that repository.
   |-->
  <mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
    <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <!-- https://maven.aliyun.com/repository/public/ -->
        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
        <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>
  <!-- profiles
   | This is a list of profiles which can be activated in a variety of ways, and which can modify
   | the build process. Profiles provided in the settings.xml are intended to provide local machine-
   | specific paths and repository locations which allow the build to work in the local environment.
   |
   | For example, if you have an integration testing plugin - like cactus - that needs to know where
   | your Tomcat instance is installed, you can provide a variable here such that the variable is
   | dereferenced during the build process to configure the cactus plugin.
   |
   | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
   | section of this document (settings.xml) - will be discussed later. Another way essentially
   | relies on the detection of a system property, either matching a particular value for the property,
   | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
   | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
   | Finally, the list of active profiles can be specified directly from the command line.
   |
   | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
   |       repositories, plugin repositories, and free-form properties to be used as configuration
   |       variables for plugins in the POM.
   |
   |-->
  <profiles>
    <!-- profile
     | Specifies a set of introductions to the build process, to be activated using one or more of the
     | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
     | or the command line, profiles have to have an ID that is unique.
     |
     | An encouraged best practice for profile identification is to use a consistent naming convention
     | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
     | This will make it more intuitive to understand what the set of introduced profiles is attempting
     | to accomplish, particularly when you only have a list of profile id's for debug.
     |
     | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
    <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>
    -->
    <profile>
        <id>jdk1.8</id>
        <activation>
            <activeByDefault>true</activeByDefault>
            <jdk>1.8</jdk>
        </activation>
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
            <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
        </properties>
    </profile>

    <profile>
        <id>dev</id>
        <repositories>
            <repository>
                <id>nexus</id>
                <url>http://nexus.topcheer.xyz:8081/nexus/content/groups/public/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>public</id>
                <name>Public Repositories</name>
                <url>http://nexus.topcheer.xyz:8081/nexus/content/groups/public/</url>
            </pluginRepository>
        </pluginRepositories>
    </profile>

    <profile>
        <id>ali</id>
        <repositories>
            <repository>
                <id>alimaven</id>
                <name>aliyun maven</name>
                <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>alimaven</id>
                <name>aliyun maven</name>
                <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            </pluginRepository>
        </pluginRepositories>
    </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>
  -->
    <activeProfiles>
        <activeProfile>jdk1.8</activeProfile>
        <activeProfile>ali</activeProfile>
        <activeProfile>dev</activeProfile>
    </activeProfiles>
</settings>

 

概要

settings.xml有什么用?

如果在Eclipse中使用過Maven插件,想必會有這個經驗:配置settings.xml文件的路徑。
Paste_Image.png
settings.xml文件是干什么的,為什么要配置它呢?
從settings.xml的文件名就可以看出,它是用來設置maven參數的配置文件。並且,settings.xml是maven的全局配置文件。而pom.xml文件是所在項目的局部配置。
Settings.xml中包含類似本地倉儲位置、修改遠程倉儲服務器、認證信息等配置。

settings.xml文件位置

settings.xml文件一般存在於兩個位置:
全局配置: ${M2_HOME}/conf/settings.xml
用戶配置: user.home/.m2/settings.xmlnoteuser.home/.m2/settings.xmlnote:用戶配置優先於全局配置。{user.home} 和和所有其他系統屬性只能在3.0+版本上使用。請注意windows和Linux使用變量的區別。

配置優先級

需要注意的是:局部配置優先於全局配置
配置優先級從高到低:pom.xml> user settings > global settings
如果這些文件同時存在,在應用配置時,會合並它們的內容,如果有重復的配置,優先級高的配置會覆蓋優先級低的。

settings.xml元素詳解

頂級元素概覽

下面列舉了settings.xml中的頂級元素

<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
                          https://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository/>
  <interactiveMode/>
  <usePluginRegistry/>
  <offline/>
  <pluginGroups/>
  <servers/>
  <mirrors/>
  <proxies/>
  <profiles/>
  <activeProfiles/>
</settings>

LocalRepository

作用:該值表示構建系統本地倉庫的路徑。
其默認值:~/.m2/repository。

<localRepository>${user.home}/.m2/repository</localRepository>

InteractiveMode

作用:表示maven是否需要和用戶交互以獲得輸入。
如果maven需要和用戶交互以獲得輸入,則設置成true,反之則應為false。默認為true。

<interactiveMode>true</interactiveMode>

UsePluginRegistry

作用:maven是否需要使用plugin-registry.xml文件來管理插件版本。
如果需要讓maven使用文件~/.m2/plugin-registry.xml來管理插件版本,則設為true。默認為false。

<usePluginRegistry>false</usePluginRegistry>

Offline

作用:表示maven是否需要在離線模式下運行。
如果構建系統需要在離線模式下運行,則為true,默認為false。
當由於網絡設置原因或者安全因素,構建服務器不能連接遠程倉庫的時候,該配置就十分有用。

<offline>false</offline>

PluginGroups

作用:當插件的組織id(groupId)沒有顯式提供時,供搜尋插件組織Id(groupId)的列表。
該元素包含一個pluginGroup元素列表,每個子元素包含了一個組織Id(groupId)。
當我們使用某個插件,並且沒有在命令行為其提供組織Id(groupId)的時候,Maven就會使用該列表。默認情況下該列表包含了org.apache.maven.pluginsorg.codehaus.mojo

<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
                      https://maven.apache.org/xsd/settings-1.0.0.xsd">
  ...
  <pluginGroups>
    <!--plugin的組織Id(groupId) -->
    <pluginGroup>org.codehaus.mojo</pluginGroup>
  </pluginGroups>
  ...
</settings>

Servers

作用:一般,倉庫的下載和部署是在pom.xml文件中的repositoriesdistributionManagement元素中定義的。然而,一般類似用戶名、密碼(有些倉庫訪問是需要安全認證的)等信息不應該在pom.xml文件中配置,這些信息可以配置在settings.xml中。

<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
                      https://maven.apache.org/xsd/settings-1.0.0.xsd">
  ...
  <!--配置服務端的一些設置。一些設置如安全證書不應該和pom.xml一起分發。這種類型的信息應該存在於構建服務器上的settings.xml文件中。 -->
  <servers>
    <!--服務器元素包含配置服務器時需要的信息 -->
    <server>
      <!--這是server的id(注意不是用戶登陸的id),該id與distributionManagement中repository元素的id相匹配。 -->
      <id>server001</id>
      <!--鑒權用戶名。鑒權用戶名和鑒權密碼表示服務器認證所需要的登錄名和密碼。 -->
      <username>my_login</username>
      <!--鑒權密碼 。鑒權用戶名和鑒權密碼表示服務器認證所需要的登錄名和密碼。密碼加密功能已被添加到2.1.0 +。詳情請訪問密碼加密頁面 -->
      <password>my_password</password>
      <!--鑒權時使用的私鑰位置。和前兩個元素類似,私鑰位置和私鑰密碼指定了一個私鑰的路徑(默認是${user.home}/.ssh/id_dsa)以及如果需要的話,一個密語。將來passphrase和password元素可能會被提取到外部,但目前它們必須在settings.xml文件以純文本的形式聲明。 -->
      <privateKey>${usr.home}/.ssh/id_dsa</privateKey>
      <!--鑒權時使用的私鑰密碼。 -->
      <passphrase>some_passphrase</passphrase>
      <!--文件被創建時的權限。如果在部署的時候會創建一個倉庫文件或者目錄,這時候就可以使用權限(permission)。這兩個元素合法的值是一個三位數字,其對應了unix文件系統的權限,如664,或者775。 -->
      <filePermissions>664</filePermissions>
      <!--目錄被創建時的權限。 -->
      <directoryPermissions>775</directoryPermissions>
    </server>
  </servers>
  ...
</settings>

Mirrors

作用:為倉庫列表配置的下載鏡像列表。

<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
                      https://maven.apache.org/xsd/settings-1.0.0.xsd">
  ...
  <mirrors>
    <!-- 給定倉庫的下載鏡像。 -->
    <mirror>
      <!-- 該鏡像的唯一標識符。id用來區分不同的mirror元素。 -->
      <id>planetmirror.com</id>
      <!-- 鏡像名稱 -->
      <name>PlanetMirror Australia</name>
      <!-- 該鏡像的URL。構建系統會優先考慮使用該URL,而非使用默認的服務器URL。 -->
      <url>http://downloads.planetmirror.com/pub/maven2</url>
      <!-- 被鏡像的服務器的id。例如,如果我們要設置了一個Maven中央倉庫(http://repo.maven.apache.org/maven2/)的鏡像,就需要將該元素設置成central。這必須和中央倉庫的id central完全一致。 -->
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>
  ...
</settings>

Proxies

作用:用來配置不同的代理。

<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
                      https://maven.apache.org/xsd/settings-1.0.0.xsd">
  ...
  <proxies>
    <!--代理元素包含配置代理時需要的信息 -->
    <proxy>
      <!--代理的唯一定義符,用來區分不同的代理元素。 -->
      <id>myproxy</id>
      <!--該代理是否是激活的那個。true則激活代理。當我們聲明了一組代理,而某個時候只需要激活一個代理的時候,該元素就可以派上用處。 -->
      <active>true</active>
      <!--代理的協議。 協議://主機名:端口,分隔成離散的元素以方便配置。 -->
      <protocol>http</protocol>
      <!--代理的主機名。協議://主機名:端口,分隔成離散的元素以方便配置。 -->
      <host>proxy.somewhere.com</host>
      <!--代理的端口。協議://主機名:端口,分隔成離散的元素以方便配置。 -->
      <port>8080</port>
      <!--代理的用戶名,用戶名和密碼表示代理服務器認證的登錄名和密碼。 -->
      <username>proxyuser</username>
      <!--代理的密碼,用戶名和密碼表示代理服務器認證的登錄名和密碼。 -->
      <password>somepassword</password>
      <!--不該被代理的主機名列表。該列表的分隔符由代理服務器指定;例子中使用了豎線分隔符,使用逗號分隔也很常見。 -->
      <nonProxyHosts>*.google.com|ibiblio.org</nonProxyHosts>
    </proxy>
  </proxies>
  ...
</settings>

Profiles

作用:根據環境參數來調整構建配置的列表。
settings.xml中的profile元素是pom.xmlprofile元素的裁剪版本
它包含了idactivationrepositoriespluginRepositories和 properties元素。這里的profile元素只包含這五個子元素是因為這里只關心構建系統這個整體(這正是settings.xml文件的角色定位),而非單獨的項目對象模型設置。如果一個settings.xml中的profile被激活,它的值會覆蓋任何其它定義在pom.xml中帶有相同id的profile

<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
                      https://maven.apache.org/xsd/settings-1.0.0.xsd">
  ...
  <profiles>
    <profile>
      <!-- profile的唯一標識 -->
      <id>test</id>
      <!-- 自動觸發profile的條件邏輯 -->
      <activation />
      <!-- 擴展屬性列表 -->
      <properties />
      <!-- 遠程倉庫列表 -->
      <repositories />
      <!-- 插件倉庫列表 -->
      <pluginRepositories />
    </profile>
  </profiles>
  ...
</settings>

 

Activation

作用:自動觸發profile的條件邏輯。
pom.xml中的profile一樣,profile的作用在於它能夠在某些特定的環境中自動使用某些特定的值;這些環境通過activation元素指定。
activation元素並不是激活profile的唯一方式。settings.xml文件中的activeProfile元素可以包含profileidprofile也可以通過在命令行,使用-P標記和逗號分隔的列表來顯式的激活(如,-P test)。

<activation>
  <!--profile默認是否激活的標識 -->
  <activeByDefault>false</activeByDefault>
  <!--當匹配的jdk被檢測到,profile被激活。例如,1.4激活JDK1.4,1.4.0_2,而!1.4激活所有版本不是以1.4開頭的JDK。 -->
  <jdk>1.5</jdk>
  <!--當匹配的操作系統屬性被檢測到,profile被激活。os元素可以定義一些操作系統相關的屬性。 -->
  <os>
    <!--激活profile的操作系統的名字 -->
    <name>Windows XP</name>
    <!--激活profile的操作系統所屬家族(如 'windows') -->
    <family>Windows</family>
    <!--激活profile的操作系統體系結構 -->
    <arch>x86</arch>
    <!--激活profile的操作系統版本 -->
    <version>5.1.2600</version>
  </os>
  <!--如果Maven檢測到某一個屬性(其值可以在POM中通過${name}引用),其擁有對應的name = 值,Profile就會被激活。如果值字段是空的,那么存在屬性名稱字段就會激活profile,否則按區分大小寫方式匹配屬性值字段 -->
  <property>
    <!--激活profile的屬性的名稱 -->
    <name>mavenVersion</name>
    <!--激活profile的屬性的值 -->
    <value>2.0.3</value>
  </property>
  <!--提供一個文件名,通過檢測該文件的存在或不存在來激活profile。missing檢查文件是否存在,如果不存在則激活profile。另一方面,exists則會檢查文件是否存在,如果存在則激活profile。 -->
  <file>
    <!--如果指定的文件存在,則激活profile。 -->
    <exists>${basedir}/file2.properties</exists>
    <!--如果指定的文件不存在,則激活profile。 -->
    <missing>${basedir}/file1.properties</missing>
  </file>
</activation>

 

注:在maven工程的pom.xml所在目錄下執行mvn help:active-profiles命令可以查看中央倉儲的profile是否在工程中生效。

properties

作用:對應profile的擴展屬性列表。
maven屬性和ant中的屬性一樣,可以用來存放一些值。這些值可以在pom.xml中的任何地方使用標記${X}來使用,這里X是指屬性的名稱。屬性有五種不同的形式,並且都能在settings.xml文件中訪問。

<!-- 
  1. env.X: 在一個變量前加上"env."的前綴,會返回一個shell環境變量。例如,"env.PATH"指代了$path環境變量(在Windows上是%PATH%)。 
  2. project.x:指代了POM中對應的元素值。例如: <project><version>1.0</version></project>通過${project.version}獲得version的值。 
  3. settings.x: 指代了settings.xml中對應元素的值。例如:<settings><offline>false</offline></settings>通過 ${settings.offline}獲得offline的值。 
  4. Java System Properties: 所有可通過java.lang.System.getProperties()訪問的屬性都能在POM中使用該形式訪問,例如 ${java.home}。 
  5. x: 在<properties/>元素中,或者外部文件中設置,以${someVar}的形式使用。
 -->
<properties>
  <user.install>${user.home}/our-project</user.install>
</properties>

 

注:如果該profile被激活,則可以在pom.xml中使用${user.install}。

Repositories

作用:遠程倉庫列表,它是maven用來填充構建系統本地倉庫所使用的一組遠程倉庫。

<repositories>
  <!--包含需要連接到遠程倉庫的信息 -->
  <repository>
    <!--遠程倉庫唯一標識 -->
    <id>codehausSnapshots</id>
    <!--遠程倉庫名稱 -->
    <name>Codehaus Snapshots</name>
    <!--如何處理遠程倉庫里發布版本的下載 -->
    <releases>
      <!--true或者false表示該倉庫是否為下載某種類型構件(發布版,快照版)開啟。 -->
      <enabled>false</enabled>
      <!--該元素指定更新發生的頻率。Maven會比較本地POM和遠程POM的時間戳。這里的選項是:always(一直),daily(默認,每日),interval:X(這里X是以分鍾為單位的時間間隔),或者never(從不)。 -->
      <updatePolicy>always</updatePolicy>
      <!--當Maven驗證構件校驗文件失敗時該怎么做-ignore(忽略),fail(失敗),或者warn(警告)。 -->
      <checksumPolicy>warn</checksumPolicy>
    </releases>
    <!--如何處理遠程倉庫里快照版本的下載。有了releases和snapshots這兩組配置,POM就可以在每個單獨的倉庫中,為每種類型的構件采取不同的策略。例如,可能有人會決定只為開發目的開啟對快照版本下載的支持。參見repositories/repository/releases元素 -->
    <snapshots>
      <enabled />
      <updatePolicy />
      <checksumPolicy />
    </snapshots>
    <!--遠程倉庫URL,按protocol://hostname/path形式 -->
    <url>http://snapshots.maven.codehaus.org/maven2</url>
    <!--用於定位和排序構件的倉庫布局類型-可以是default(默認)或者legacy(遺留)。Maven 2為其倉庫提供了一個默認的布局;然而,Maven 1.x有一種不同的布局。我們可以使用該元素指定布局是default(默認)還是legacy(遺留)。 -->
    <layout>default</layout>
  </repository>
</repositories>

 

pluginRepositories

作用:發現插件的遠程倉庫列表。
repository類似,只是repository是管理jar包依賴的倉庫,pluginRepositories則是管理插件的倉庫。
maven插件是一種特殊類型的構件。由於這個原因,插件倉庫獨立於其它倉庫。pluginRepositories元素的結構和repositories元素的結構類似。每個pluginRepository元素指定一個Maven可以用來尋找新插件的遠程地址。

<pluginRepositories>
  <!-- 包含需要連接到遠程插件倉庫的信息.參見profiles/profile/repositories/repository元素的說明 -->
  <pluginRepository>
    <releases>
      <enabled />
      <updatePolicy />
      <checksumPolicy />
    </releases>
    <snapshots>
      <enabled />
      <updatePolicy />
      <checksumPolicy />
    </snapshots>
    <id />
    <name />
    <url />
    <layout />
  </pluginRepository>
</pluginRepositories>

 

ActiveProfiles

作用:手動激活profiles的列表,按照profile被應用的順序定義activeProfile
該元素包含了一組activeProfile元素,每個activeProfile都含有一個profile id。任何在activeProfile中定義的profile id,不論環境設置如何,其對應的 profile都會被激活。如果沒有匹配的profile,則什么都不會發生。
例如,env-test是一個activeProfile,則在pom.xml(或者profile.xml)中對應id的profile會被激活。如果運行過程中找不到這樣一個profile,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
                      https://maven.apache.org/xsd/settings-1.0.0.xsd">
  ...
  <activeProfiles>
    <!-- 要激活的profile id -->
    <activeProfile>env-test</activeProfile>
  </activeProfiles>
  ...
</settings>

 

至此,maven settings.xml中的標簽都講解完畢,希望對大家有所幫助。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM