`

Maven settings.xml 配置详解

阅读更多

简单介绍一下几个主要的配置因素:
localRepository:表示本地库的保存位置,也就是maven2主要的jar保存位置,默认在${user.dir}/.m2/repository,如果需要另外设置,就换成其他的路径。
offline:如果不想每次编译,都去查找远程中心库,那就设置为true。当然前提是你已经下载了必须的依赖包。
Servers
   在POM中的 distributionManagement元素定义了开发库。然而,特定的username和pwd不能使用于pom.xml,所以通过此配置来保存server信息
  <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> 

  • id:server 的id,用于匹配distributionManagement库id,比较重要。
  • username, password:用于登陆此服务器的用户名和密码
  • privateKey, passphrase:设置private key,以及passphrase
  • filePermissions, directoryPermissions:当库文件或者目录创建后,需要使用权限进行访问。参照unix文件许可,如664和775

Mirrors 
表示镜像库,指定库的镜像,用于增加其他库
  <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 
此设置,主要用于无法直接访问中心的库用户配置。
  <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后,并不会生效,需要通过满足条件来激活。
 repositories 和pluginRepositories 
 定义其他开发库和插件开发库。对于团队来说,肯定有自己的开发库。可以通过此配置来定义。
 如下的配置,定义了本地开发库,用于release 发布。
    <repositories>
        <repository>
          <id>repo-local</id>
       <name>Internal 开发库</name>
       <url>http://192.168.0.2:8082/repo-local</url>
          <releases>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
            <checksumPolicy>warn</checksumPolicy>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <layout>default</layout>
        </repository>
      </repositories>
      <pluginRepositories>
    <pluginRepository>
    <id>repo-local</id>
    <name>Internal 开发库</name>
    <url>http://192.168.0.2:8082/repo-local</url>
    <releases>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
            <checksumPolicy>warn</checksumPolicy>
    </releases>
    <snapshots>
    <enabled>false</enabled>
    </snapshots>
    <layout>default</layout>
    </pluginRepository>
    </pluginRepositories>
releases, snapshots:每个产品的版本的Release或者snapshot(注:release和snapshot的区别,release一般是比较稳定的版本,而snapshot基本上不稳定,只是作为快照)

properties
  maven 的properties作为placeholder值,如ant的properties。
包括以下的5种类型值:

  1. env.X,返回当前的环境变量
  2. project.x:返回pom中定义的元素值,如project.version
  3. settings.x:返回settings.xml中定义的元素
  4. java 系统属性:所有经过java.lang.System.getProperties()返回的值
  5. x:用户自己设定的值

Activation 
  用于激活此profile
  <activation>
        <activeByDefault>false</activeByDefault>
        <jdk>1.5</jdk>
        <os>
          <name>Windows XP</name>
          <family>Windows</family>
          <arch>x86</arch>
          <version>5.1.2600</version>
        </os>
        <property>
          <name>mavenVersion</name>
          <value>2.0.3</value>
        </property>
        <file>
          <exists>${basedir}/file2.properties</exists>
          <missing>${basedir}/file1.properties</missing>
        </file>
      </activation>

  • jdk:如果匹配指定的jdk版本,将会激活
  • os:操作系统
  • property:如果maven能检测到相应的属性
  • file: 用于判断文件是否存在或者不存在


除了使用activation来激活profile,同样可以通过activeProfiles来激活
Active Profiles
表示激活的profile,通过profile id来指定。
  <activeProfiles>
    <activeProfile>env-test</activeProfile> 指定的profile id
  </activeProfiles>

分享到:
评论

相关推荐

    开源中国Maven settings.xml配置

    开源中国Maven库settings.xml配置详解,用户只需配置自己本机的localRepository即可使用。

    Maven默认中央仓库(settings.xml 配置详解)

    主要介绍了Maven默认中央仓库(settings.xml 配置详解),小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

    maven 配置文件:settings.xml详解版,只需修改本地仓库路径即可使用

    使用eclipse整合maven时所需要使用的配置文件;只需修改文件中的本地仓库路径即可完成整合,java初学者必选。

    详解Maven settings.xml配置(指定本地仓库、阿里云镜像设置)

    主要介绍了详解Maven settings.xml配置(指定本地仓库、阿里云镜像设置),小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

    Maven setting.xml配置文件详解

    本篇文章主要介绍了Maven setting.xml 配置文件详解,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

    settings.xml

    maven配置文件setting.xml的说明,包含了maven标签的含义详解,包含了各个地方的仓库的地址,归类大全。由于国内oschina的maven服务器很早之前就关了,所以maven下载大部分都是阿里云,文件中不仅包含了阿里云,还有...

    Maven权威指南 很精典的学习教程,比ANT更好用

    Maven权威指南 Authors Tim O'Brien (Sonatype, Inc.) , John Casey (Sonatype, Inc.) , Brian Fox (Sonatype, Inc.) , Bruce Snyder () , Jason Van Zyl (Sonatype, Inc.) , Juven Xu () Abstract Maven权威指南...

    maven Pom详解.pdf

    maven pom 详解 maven2 比起maven1 来说,需要配置的文件少多了,主要集中在pom.xml和settings.xml中

    Nexus&maven;&pom;之间配置详解

    用于说明Nexus&maven;&pom;之间配置详解。包括nexus各个仓库的作用、每种类型所代表的含义;maven中的settings.xml与nexus中的仓库如何进行匹配的。settings.xml与pom.xml是如何匹配的等。

    maenv settings

    Maven库阿里云settings.xml配置详解,不要任何配置直接可以用,eclipse配置描述:windows--&gt;Preferences--&gt;Maenv--&gt;User Setting

    jgitflow-example

    在 Maven 设置文件(每个用户:~/.m2/settings.xml;全局:$M2_HOME/conf/settings.xml)或本地(settings.xml)中,您可以提供自定义 pluginGroups 部分,列出插件 groupIds您要搜索(每个 groupId 都在其自己的 ...

Global site tag (gtag.js) - Google Analytics