Maven--setting.xml详解

基本上是对官网的翻译和简化 http://maven.apache.org/settings.html

Introduction

  • settings.xml是maven的全局配置文件
  • pom.xml文件是所在项目的局部配置
  • settings.xml文件位置
    1. global settings : ${maven.home}/conf/settings.xml
    2. user settings : ~/.m2/settings.xml //~表示${user.home} 下同
  • 优先级: pom.xml > user settings > global settings

Settings Details

top elements & simple value

<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
                          https://maven.apache.org/xsd/settings-1.0.0.xsd">
      <!-- 本地仓库。默认值:~/.m2/repository -->
      <localRepository/> 
      <!-- 与用户交互以获得输入。默认false -->
      <interactiveMode/>
      <!-- 使用~/.m2/plugin-registry.xml来管理插件版本。默认false -->
      <usePluginRegistry/>
      <!-- 离线模式。默认false。理解不了 -->
      <offline/>
      <!-- -->
      <pluginGroups/>
      <!-- -->
      <servers/>
      <!-- -->
      <mirrors/>
      <!-- -->
      <proxies/>
      <!-- -->
      <profiles/>
      <!-- -->
      <activeProfiles/>
    </settings>

Plugin Groups

<!-- 给命令行下运行的插件,提供默认的groudId。
默认已经包含:org.apache.maven.plugins,org.codehaus.mojo -->
<pluginGroups>
    <!-- mvn jetty:run 等效于 org.mortbay.jetty:jetty-maven-plugin:run-->
    <pluginGroup>org.mortbay.jetty</pluginGroup>
</pluginGroups>

servers

<!-- The repositories for download and deployment are defined by the repositories and distributionManagement elements of the POM. -->
<servers>
    <server>
    <!-- This is the ID of the server (not of the user to login as) .
    it matches the id element of the repository/mirror -->
      <id>server001</id>
      <username>my_login</username>
      <password>my_password</password>
      <privateKey>${user.home}/.ssh/id_dsa</privateKey>
      <passphrase>some_passphrase</passphrase>
      <filePermissions>664</filePermissions>
      <directoryPermissions>775</directoryPermissions>
      <configuration></configuration>
    </server>
</servers>

Mirrors

  <mirrors>
  <!--仓库的下载镜像 -->
    <mirror>
      <!-- 镜像的id -->
      <id>planetmirror.com</id>
      <!-- 镜像的名称 -->
      <name>PlanetMirror Australia</name>
      <!-- 镜像的url -->
      <url>http://downloads.planetmirror.com/pub/maven2</url>
      <!-- 被镜像仓库的id -->
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>

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>

Profiles

  <profiles>
    <profile>
      <id>test</id>
      <activation>
      <!-- 也可以在命令行中指定:-P test -->
        <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>
      ...
    </profile>
  </profiles>

Properties

  1. env.X: the shell’s environment variable. ${env.PATH}
  2. project.x:pom.xml中对应元素值。${project.version}.
  3. settings.x: settings.xml中对应元素的值。${settings.offline}
  4. Java System Properties: java.lang.System.getProperties的值。${java.home}
  5. x: Set within a properties element or an external files, the value may be used as ${someVar}.
      <properties>
          <!-- ${user.install} is accessible from a POM if this profile is active. -->
        <user.install>${user.home}/our-project</user.install>
      </properties>

Profiles.repositories & pluginRepositories

  <profiles>
    <profile>
      ...
      <repositories>
        <repository>
          <id>codehausSnapshots</id>
          <name>Codehaus Snapshots</name>
          <releases>
            <enabled>false</enabled>
            <updatePolicy>always</updatePolicy>
            <checksumPolicy>warn</checksumPolicy>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
            <checksumPolicy>fail</checksumPolicy>
          </snapshots>
          <url>http://snapshots.maven.codehaus.org/maven2</url>
          <layout>default</layout>
        </repository>
      </repositories>
      <pluginRepositories>
        ...
      </pluginRepositories>
      ...
    </profile>
  </profiles>

Active Profiles

  <activeProfiles>
    <activeProfile>env-test</activeProfile>
  </activeProfiles>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值