maven settings.xml详解

maven settings.xml详解

setting.xml配置文件

http://blog.csdn.net/u012152619/article/details/51485152

https://www.cnblogs.com/yanghongfei/p/6995613.html

maven的配置文件settings.xml存在于两个地方:

1.安装的地方:${M2_HOME}/conf/settings.xml

2.用户的目录:${user.home}/.m2/settings.xml

前者又被叫做全局配置,对操作系统的所有使用者生效;后者被称为用户配置,只对当前操作系统的使用者生效。如果两者都存在,它们的内容将被合并,并且用户范围的settings.xml会覆盖全局的settings.xml。

Maven安装后,用户目录下不会自动生成settings.xml,只有全局配置文件。如果需要创建用户范围的settings.xml,可以将安装路径下的settings复制到目录${user.home}/.m2/。Maven默认的settings.xml是一个包含了注释和例子的模板,可以快速的修改它来达到你的要求。

全局配置一旦更改,所有的用户都会受到影响,而且如果maven进行升级,所有的配置都会被清除,所以要提前复制和备份${M2_HOME}/conf/settings.xml文件,一般情况下不推荐配置全局的settings.xml。

 

[html]  view plain  copy
 
 print?
  1. xml version="1.0" encoding="UTF-8"?>  
  2.     
  3. <settings   xmlns="http://maven.apache.org/POM/4.0.0"    
  4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
  5.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">  
  6.         
  7.       
  8.     <localRepository>usr/local/mavenlocalRepository>  
  9.         
  10.       
  11.     <interactiveMode>trueinteractiveMode>  
  12.         
  13.       
  14.       
  15.       
  16.     <usePluginRegistry>falseusePluginRegistry>  
  17.         
  18.       
  19.       
  20.     <offline>falseoffline>  
  21.         
  22.       
  23.       
  24.       
  25.       
  26.     <pluginGroups>  
  27.             
  28.           
  29.         <pluginGroup>org.codehaus.mojopluginGroup>  
  30.            
  31.     pluginGroups>  
  32.         
  33.       
  34.     <proxies>  
  35.             
  36.           
  37.         <proxy>  
  38.                 
  39.               
  40.             <id>myproxyid>  
  41.                 
  42.               
  43.             <active>trueactive>  
  44.                 
  45.               
  46.             <protocol>http://…protocol>  
  47.                 
  48.               
  49.             <host>proxy.somewhere.comhost>  
  50.                 
  51.               
  52.             <port>8080port>  
  53.                 
  54.                
  55.             <username>proxyuserusername>  
  56.                 
  57.               
  58.             <password>somepasswordpassword>  
  59.                 
  60.               
  61.             <nonProxyHosts>*.google.com|ibiblio.orgnonProxyHosts>  
  62.                 
  63.         proxy>  
  64.            
  65.     proxies>  
  66.         
  67.       
  68.     <servers>  
  69.             
  70.           
  71.         <server>  
  72.                 
  73.               
  74.             <id>server001id>  
  75.                 
  76.               
  77.             <username>my_loginusername>  
  78.                 
  79.               
  80.             <password>my_passwordpassword>  
  81.                 
  82.               
  83.               
  84.             <privateKey>${usr.home}/.ssh/id_dsaprivateKey>  
  85.                 
  86.               
  87.             <passphrase>some_passphrasepassphrase>  
  88.                 
  89.               
  90.               
  91.             <filePermissions>664filePermissions>  
  92.                 
  93.               
  94.             <directoryPermissions>775directoryPermissions>  
  95.                 
  96.               
  97.             <configuration>configuration>  
  98.                 
  99.         server>  
  100.            
  101.     servers>  
  102.         
  103.       
  104.     <mirrors>  
  105.             
  106.           
  107.         <mirror>  
  108.                 
  109.               
  110.             <id>planetmirror.comid>  
  111.                 
  112.               
  113.             <name>PlanetMirror Australianame>  
  114.                 
  115.               
  116.             <url>http://downloads.planetmirror.com/pub/maven2url>  
  117.                 
  118.               
  119.               
  120.             <mirrorOf>centralmirrorOf>  
  121.                 
  122.         mirror>  
  123.            
  124.     mirrors>  
  125.         
  126.       
  127.       
  128.       
  129.       
  130.     <profiles>  
  131.             
  132.           
  133.         <profile>  
  134.                 
  135.               
  136.             <id>testid>  
  137.                 
  138.               
  139.               
  140.               
  141.               
  142.             <activation>  
  143.                     
  144.                   
  145.                 <activeByDefault>falseactiveByDefault>  
  146.                     
  147.                   
  148.                 <jdk>1.7jdk>  
  149.                     
  150.                   
  151.                 <os>  
  152.                         
  153.                       
  154.                     <name>Windows XPname>  
  155.                         
  156.                       
  157.                     <family>Windowsfamily>  
  158.                         
  159.                       
  160.                     <arch>x86arch>  
  161.                         
  162.                       
  163.                     <version>5.1.2600version>  
  164.                           
  165.                 os>  
  166.                     
  167.                   
  168.                   
  169.                 <property>  
  170.                         
  171.                       
  172.                     <name>mavenVersionname>  
  173.                         
  174.                       
  175.                     <value>2.0.3value>  
  176.                           
  177.                 property>  
  178.                     
  179.                   
  180.                   
  181.                 <file>  
  182.                         
  183.                       
  184.                     <exists>/usr/local/hudson/hudson-home/jobs/maven-guide-zh-to-production/workspace/exists>  
  185.                         
  186.                       
  187.                     <missing>/usr/local/hudson/hudson-home/jobs/maven-guide-zh-to-production/workspace/missing>  
  188.                           
  189.                 file>  
  190.                      
  191.             activation>  
  192.                 
  193.                
  194.               
  195.                
  196.               
  197.               
  198.               
  199.               
  200.               
  201.             <properties>  
  202.               
  203.                   
  204.                 <user.install>usr/local/winner/jobs/maven-guideuser.install>  
  205.                      
  206.             properties>  
  207.                 
  208.               
  209.             <repositories>  
  210.                     
  211.                   
  212.                 <repository>  
  213.                         
  214.                       
  215.                     <id>codehausSnapshotsid>  
  216.                         
  217.                       
  218.                     <name>Codehaus Snapshotsname>  
  219.                         
  220.                       
  221.                     <releases>  
  222.                             
  223.                           
  224.                         <enabled>falseenabled>  
  225.                             
  226.                           
  227.                           
  228.                         <updatePolicy>alwaysupdatePolicy>  
  229.                             
  230.                           
  231.                           
  232.                         <checksumPolicy>warnchecksumPolicy>  
  233.                                
  234.                     releases>  
  235.                         
  236.                       
  237.                       
  238.                     <snapshots>  
  239.                                 
  240.                         <enabled />  
  241.                         <updatePolicy />  
  242.                         <checksumPolicy />  
  243.                                
  244.                     snapshots>  
  245.                         
  246.                       
  247.                     <url>http://snapshots.maven.codehaus.org/maven2url>  
  248.                         
  249.                       
  250.                       
  251.                     <layout>defaultlayout>  
  252.                           
  253.                 repository>  
  254.                      
  255.             repositories>  
  256.                 
  257.               
  258.               
  259.               
  260.             <pluginRepositories>  
  261.                     
  262.                   
  263.                 <pluginRepository>  
  264.                     <releases>  
  265.                         <enabled />  
  266.                         <updatePolicy />  
  267.                         <checksumPolicy />  
  268.                     releases>  
  269.                            
  270.                     <snapshots>  
  271.                         <enabled />  
  272.                         <updatePolicy />  
  273.                         <checksumPolicy />  
  274.                     snapshots>  
  275.                            
  276.                     <id />  
  277.                     <name />  
  278.                     <url />  
  279.                     <layout />  
  280.                 pluginRepository>  
  281.                           
  282.             pluginRepositories>  
  283.                 
  284.               
  285.               
  286.               
  287.               
  288.             <activeProfiles>  
  289.                       
  290.                 <activeProfile>env-testactiveProfile>  
  291.                      
  292.             activeProfiles>  
  293.                 
  294.         profile>  
  295.            
  296.     profiles>  
  297.         
  298. settings>  


上面的配置文件对各个节点的含义及作用都有注解。实际应用中,经常使用的是有限几个节点,其他节点使用默认值足够应对大部分的应用场景。

 

 

节点

在仓库的配置一节中,已经对setting.xml中的常用节点做了详细的说明。在这里需要特别介绍一下的是节点的配置,profile是maven的一个重要特性。

节点包含了激活(activation)仓库(repositories)插件仓库(pluginRepositories)属性(properties)共四个子元素元素。profile元素仅包含这四个元素是因为他们涉及到整个的构建系统,而不是个别的项目级别的POM配置。

profile可以让maven能够自动适应外部的环境变化,比如同一个项目,在Linux下编译linux的版本,在win下编译win的版本等。一个项目可以设置多个profile,也可以在同一时间设置多个profile被激活(active)的。自动激活的 profile的条件可以是各种各样的设定条件,组合放置在activation节点中,也可以通过命令行直接指定。如果认为profile设置比较复杂,可以将所有的profiles内容移动到专门的 profiles.xml 文件中,不过记得和pom.xml放在一起。

activation节点是设置该profile在什么条件下会被激活,常见的条件有如下几个:

1.   os

判断操作系统相关的参数,它包含如下可以自由组合的子节点元素

message - 规则失败之后显示的消息

arch - 匹配cpu结构,常见为x86

family - 匹配操作系统家族,常见的取值为:dos,mac,netware,os/2,unix,windows,win9x,os/400等

name - 匹配操作系统的名字

version - 匹配的操作系统版本号

display - 检测到操作系统之后显示的信息

2.   jdk

检查jdk版本,可以用区间表示。

3.   property

检查属性值,本节点可以包含name和value两个子节点。

4.   file

检查文件相关内容,包含两个子节点:exists和missing,用于分别检查文件存在和不存在两种情况。

如果settings中的profile被激活,那么它的值将覆盖POM或者profiles.xml中的任何相等ID的profiles

如果想要某个profile默认处于激活状态,可以在中将该profile的id放进去。这样,不论环境设置如何,其对应的 profile都会被激活。

你可能感兴趣的:(Scala开发)