maven配置文件settings.xml详解

maven运行时的配置文件settings.xml

安装位置

  1. 全局配置:${maven_home}/config/settings.xml
  2. 用户配置:~/.m2/settings.xml

如果全局配置与用户配置同时存在,会进行合并,相同配置则以用户配置优先。

配置节点


      
      
      
      
      
      
      
      
      
    

localRepository

本地仓库路径,不配置则默认为${user.home}/.m2/repository

interactiveMode

交互模式,是否接受用户输入,默认为true

offline

是否在离线模式下运行,默认是false

pluginGroups

插件。通过在pluginGroup节点下配置id标识,在命令行中使用到的插件需要在这里配置。注:org.apache.maven.plugins 和 org.codehaus.mojo里面的差价自动包含不需要配置。如下配置:


  ...
  
    org.eclipse.jetty
  
  ...

如上配置可以在命令行执行如下命令:

mvn jetty:run

servers

在项目的POM中可以配置上传和下载( repositories and distributionManagement )的仓库,但是仓库对应的用户名、密码、秘钥、权限等敏感信息应当在构建服务器上配置,即在本节点之下。


  ...
  
    
      server001
      my_login
      my_password
      ${user.home}/.ssh/id_dsa
      some_passphrase
      664
      775
      
    
  
  ...

  • id:服务器的id,需要与仓库和镜像中对应(repository/mirror)

mirrors

镜像仓库地址配置,参考地址


  ...
  
    
      planetmirror.com
      PlanetMirror Australia
      http://downloads.planetmirror.com/pub/maven2
      central
    
  
  ...

  • id:多个竟像时,id不能重复
  • mirrorOf:当前id对应的镜像,不能与id相同

proxies

代理信息的配置


  ...
  
    
      myproxy
      true
      http
      proxy.somewhere.com
      8080
      proxyuser
      somepassword
      *.google.com|ibiblio.org
    
  
  ...

  • active:true表示当前代理有效,false表示当前代理无效
  • nonProxyHosts:不需要通过代理的主机

profiles

这里的profile是项目中pom.xml中profile节点的缩减版,是全局配置,并不针对于单独的项目。这里的profile只包含四个子节点,分别是:activation,repositories,properties,pluginRepositories

settings.xml中profile配置会覆盖项目中pom.xml或者 profiles.xml中配置

activation

这里配置的是profile的关键信息,与pom中的profile类似,可以定义指定环境下参数使用。


  ...
  
    
      test
      
        false
        1.5
        
          Windows XP
          Windows
          x86
          5.1.2600
        
        
          mavenVersion
          2.0.3
        
        
          ${basedir}/file2.properties
          ${basedir}/file1.properties
        
      
      ...
    
  
  ...

  • jdk:jdk版本配置,只是jdk版本的前缀,会在环境中寻找符合前缀条件的jdk来使用,maven2.1开始支持区间配置。参考
  • os:系统配置。参考
  • porperty:当maven需要某些属性的时候,会从这里寻找name,value对。可以与pom中配置相同的name,对应不同的value
  • file:通过给定文件,在哪个文件存在,哪个文件不存在的情况profile生效

profile的生效与否不仅可以在这里配置,同时可以在命令行通过 -P profileid使其生效

通过maven-help-plugin查看当前构建下有效的profile

mvn help:active-profiles

properties

maven的属性通过占位符 ${X}来配置,在settings.xml中有5中不同格式的配置。

  1. env.X: Prefixing a variable with “env.” will return the shell’s environment variable. For example, path environment variable (%PATH% in Windows).
  2. project.x: A dot (.) notated path in the POM will contain the corresponding element’s value. For example: 1.0 is accessible via ${project.version}.
  3. settings.x: A dot (.) notated path in the settings.xml will contain the corresponding element’s value. For example: false is accessible via ${settings.offline}.
  4. Java System Properties: All properties accessible via java.lang.System.getProperties() are available as POM properties, such as ${java.home}.
  5. x: Set within a element or an external files, the value may be used as ${someVar}.

  ...
  
    
      ...
      
        ${user.home}/our-project
      
      ...
    
  
  ...

repository

远程仓库的配置


  ...
  
    
      ...
      
        
          codehausSnapshots
          Codehaus Snapshots
          
            false
            always
            warn
          
          
            true
            never
            fail
          
          http://snapshots.maven.codehaus.org/maven2
          default
        
      
      
        ...
      
      ...
    
  
  ...

  • enabled:true表示生效,false表示不生效
  • updatePolicy:更新策略。可选值:always, daily (默认),interval:X (X整数,单位:分钟) , never
  • checksumPolicy:部署到仓库策略。可选择:ignore,fail, warn on missing , incorrect checksums
  • layout:maven2开始又默认配置

pluginRepositories

插件仓库配置,配置类似于repositories

activeProfiles

配置哪些profile是生效的,指向是profile的id,如果配置的id不存在,不会有任何问题。配置在settings.xml、pom.xml、和profile.xml中的profile都可以在这里指定。


  ...
  
    env-test
  

其他文章列表

spring web service系列1
spring web service系列2
spring web service系列3
Nginx转发请求过程解析
Nginx中的负载均衡算法
Nginx upstream指令配置说明
Nginx中虚拟服务器server指令配置说明
Nginx中proxy_pass/proxy_redirect/proxy_set_header配置说明
Nginx中ngx_http_core_module相关指令配置说明
Java自带JVM监控工具jstat使用详细说明
Java自带JVM监控工具jps使用详细说明
Java自带故障分析工具jmap工具使用说明
Java自带故障分析工具jhat工具使用说明

你可能感兴趣的:(maven配置文件settings.xml详解)