本篇文章主要對maven中setting.xml配置文件進行解釋apache
<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>/opt/repository</localRepository>
<!--Maven是否須要和用戶交互以得到輸入。若是Maven須要和用戶交互以得到輸入,則設置成true,反之則應爲false。默認爲true。--> <interactiveMode>true</interactiveMode>
<!--Maven是否須要使用plugin-registry.xml文件來管理插件版本。若是須要讓Maven使用文件來管理插件版本,則設爲true。默認爲false。--> <usePluginRegistry>false</usePluginRegistry>
<!--表示Maven是否須要在離線模式下運行。若是構建系統須要在離線模式下運行,則爲true,默認爲false。當因爲網絡設置緣由或者安全因素,構建服務器不能鏈接遠程倉庫的時候,該配置就十分有用。 --> <offline>false</offline>
<!--當插件的組織Id(groupId)沒有顯式提供時,供搜尋插件組織Id(groupId)的列表。該元素包含一個pluginGroup元素列表,每一個子元素包含了一個組織Id(groupId)。當咱們使用某個插件,而且沒有在命令行爲其提供組織Id(groupId)的時候,Maven就會使用該列表。默認狀況下該列表包含了org.apache.maven.plugins和org.codehaus.mojo --> <pluginGroups> <!--plugin的組織Id(groupId) --> <pluginGroup>org.codehaus.mojo</pluginGroup> </pluginGroups>
<!--用來配置不一樣的代理,多代理profiles 能夠應對筆記本或移動設備的工做環境:經過簡單的設置profile id就能夠很容易的更換整個代理配置。 --> <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>
<!--配置服務端的一些設置。一些設置如安全證書不該該和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>
<!--爲倉庫列表配置的下載鏡像列表。高級設置請參閱鏡像設置頁面 --> <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.xml中的profile元素是pom.xml中profile元素的裁剪版本。它包含了id,activation, repositories, pluginRepositories和 properties元素。這裏的profile元素只包含這五個子元素是由於這裏只關心構建系統這個總體(這正是settings.xml文件的角色定位),而非單獨的項目對象模型設置。若是一個settings中的profile被激活,它的值會覆蓋任何其它定義在POM中或者profile.xml中的帶有相同id的profile。 --> <profiles> <!--根據環境參數來調整的構件的配置--> <profile> <!--該配置的惟一標識符。 --> <id>test</id>
<!--自動觸發profile的條件邏輯。Activation是profile的開啓鑰匙。如POM中的profile同樣,profile的力量來自於它可以在某些特定的環境中自動使用某些特定的值;這些環境經過activation元素指定。activation元素並非激活profile的惟一方式。settings.xml文件中的activeProfile元素能夠包含profile的id。profile也能夠經過在命令行,使用-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>
<repository> <id>nexus</id> <name>local private nexus</name> <url>http://localhost:8081/nexus/content/groups/public</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </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> <!--發現插件的遠程倉庫列表。倉庫是兩種主要構件的家。第一種構件被用做其它構件的依賴。這是中央倉庫中存儲的大部分構件類型。另一種構件類型是插件。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> </profile> </profiles>
默認配置: <activeProfiles> <activeProfile>dev</activeProfile> <!-- <activeProfile>devitcast</activeProfile>--> </activeProfiles> 配置解釋: <!--手動激活profiles的列表,按照profile被應用的順序定義activeProfile。 該元素包含了一組activeProfile元素,每一個activeProfile都含有一個profile id。任何在activeProfile中定義的profile id,不論環境設置如何,其對應的profile都會被激活。若是沒有匹配的profile,則什麼都不會發生。例如,env-test是一個activeProfile,則在pom.xml(或者profile.xml)中對應id的profile會被激活。若是運行過程當中找不到這樣一個profile,Maven則會像往常同樣運行 --> <activeProfiles> <!-- --> <activeProfile>env-test</activeProfile> </activeProfiles> </settings>
配置示例:windows
<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>/opt/repository/maven</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> --> <!-- 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> --> <server> <id>nexus</id> <username>admin</username> <password>admin123</password> </server> <server> <id>releases</id> <username>admin</username> <password>anonymous123</password> </server> <server> <id>snapshots</id> <username>admin</username> <password>anonymous123</password> </server> <server> <id>thirdparty</id> <username>admin</username> <password>anonymous123</password> </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>nexus</id> <name>internal nexus repository</name> <url>http://10.0.0.241:9999/repository/maven-public/</url> <mirrorOf>*</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> --> <!-- | 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> --> <profile> <id>apatch</id> <repositories> <repository> <id>re-apatch</id> <name>remote apatch</name> <url>http://inno.starhubdev.com/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> </profile> <profile> <id>ibiblio</id> <repositories> <repository> <id>re-ibiblio</id> <name>remote ibiblio</name> <url>https://nexus.sourcesense.com/nexus/content/repositories/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> </profile> <profile> <id>redev</id> <repositories> <repository> <id>re-nexus</id> <name>remote nexus</name> <url>http://repository.sonatype.org/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> </profile> <profile> <id>dev</id> <repositories> <repository> <id>nexus</id> <url>http://10.0.0.241:9999/nexus/content/groups/public</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus</id> <url>http://10.0.0.241:9999/nexus/content/groups/public</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <!-- activeProfiles | List of profiles that are active for all builds. | <activeProfiles> <activeProfile>alwaysActiveProfile</activeProfile> <activeProfile>anotherAlwaysActiveProfile</activeProfile> </activeProfiles> --> </settings>