maven-settings.xml的那些事

264 查看

1、代理<proxies>

<proxies>
   <proxy>
      <id>optional</id>//代理名
      <active>true</active>//true激活该代理
      <protocol>http</protocol>//代理协议
      <username>proxyuser</username>//帐号密码
      <password>proxypass</password>
      <host>proxy.host.net</host>//主机名,可以有多个,用"|"分隔
      <port>80</port>//端口号
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>//指定哪些不用代理
    </proxy>
</proxies>

2、设定本地仓库

<localRepository>D:/Development/m2/repository</localRepository>

本地仓库地址设定

3、远程仓库配置

<repositories>
    <repository>
      <id>nexus</id>//不能重复,中央仓库就是central
      <name>local private nexus</name>//描述
      <url>http://maven.oschina.net/content/groups/public/</url>//仓库地址
      <releases>
        <enabled>true</enabled>//支持获取release版本的
        <updatePolicy>daily</updatePolicy>//构件更新频率
        <checksumPolicy>ignore</checksumPolicy>//检证构建时,以何种方式提示
      </releases>
      <snapshots>
        <enabled>false</enabled>//不支持获取snapshots版本的
      </snapshots>
    </repository>
</repositories>

updatePolicy可能值

never:不更

always:每次构建都检查更新

interval:每隔X分钟检查一次

checksumPolicy可能值

warn:出错警告

fail:出错让构建失败

ignore:让maven完全忽略

4、配置仓库认证信息

  <servers>
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
  </servers>

5、设置镜像

  <mirrors>
    <mirror>
      <id>mirrorId</id>//唯一标识符
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror> 
  <mirror> 

当用户请求mirrorOf中配置的仓库时,会跳转到url中的地址

<mirrorOf>*</mirrorOf>//匹配所有远程仓库
<mirrorOf>external:*</mirrorOf>//匹配所有不在本机上的远程仓库
<mirrorOf>repo1,repo2</mirrorOf>//匹配仓库repo1和repo2
<mirrorOf>*,!repo1</mirrorOf>//除了repo1外的所有仓库

如果需要认证,则加一个id与<mirror>中一样的<server>标签配置