maven中的setting配置

Settings細節


1. setting.xml可位於兩個地方:
(a) Maven安裝目錄: $M2_HOME/conf/settings.xml
(b) 用戶特定的Settings文件: ~/.m2/settings.xml


2.setting.xml頂層元素概覽
<settings 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
http://maven.apache.org/xsd/settings-1.0.0.xsd">


<localRepository/>本地倉庫,默認.m2/repository


<interactiveMode/>是否用戶交互模式


<usePluginRegistry/>是否使用.m2/plugin-registry.xml管理插件版本


<offline/>是否離線模式


<pluginGroups/>當我們使用某個插件,並且沒有在命令行爲其提供groupId的時候,Maven就會使用該列表




<servers>
<server>
<id>server001</id>
<username>my_login</username>
<password>my_password</password>
<privateKey>${usr.home}/.ssh/id_dsa</privateKey>
<passphrase>some_passphrase</passphrase>
<filePermissions>664</filePermissions>
<directoryPermissions>775</directoryPermissions>
<configuration></configuration>
</server>
</servers>
在POM中的 distributionManagement元素定義了開發庫。然而,特定的username和pwd不能使用於pom.xml,所以通過此配置來保存server信息
id:server 的id,用於匹配distributionManagement庫id,比較重要。 
username, password:用於登陸此服務器的用戶名和密碼 
privateKey, passphrase:設置private key,以及passphrase 
filePermissions, directoryPermissions:當庫文件或者目錄創建後,需要使用權限進行訪問




<mirrors>
<mirror>
<id>planetmirror.com</id>
<name>PlanetMirror Australia</name>
<url>http://downloads.planetmirror.com/pub/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
表示鏡像庫,指定庫的鏡像,用於增加其他庫
id,name:唯一的標誌,用於區別鏡像 
url:鏡像的url 
mirrorOf:此鏡像指向的服務id 




<proxies>
<proxy>
<id>myproxy</id>
<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>
此設置,主要用於無法直接訪問中心的庫用戶配置
id:代理的標誌 
active:是否激活代理 
protocol, host, port:protocol://host:port 代理 
username, password:用戶名和密碼 
nonProxyHosts: 不需要代理的host 




<profiles/>
類似於pom.xml中的profile元素,主要包括activation,repositories,pluginRepositories 和properties元素
剛開始接觸的時候,可能會比較迷惑,其實這是maven2中比較強大的功能。從字面上來說,就是個性配置。
單獨定義profile後,並不會生效,需要通過滿足條件來激活。




<activeProfiles/>激活的Profile


</settings>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章