maven settings.xml配置简述

顶层元素概述:

localRepository:本地仓库路径

interactiveMode:是否需要用户交互(默认true)

usePluginRegistry:maven是否使用当前的工作目录下的(如/maven-guide-zh-to-production/workspace/.m2/plugin-registry.xml)来管理插件版本,默认false。

offline:是否支持离线模式(断网,连不了远程仓库,默认false。

pluginGroups:当pom.xml引入依赖时没声明groupId就会默认使用(如<pluginGroup>org.codehaus.mojo</pluginGroup>)。

 

服务器:

settings.xml可配置如下:

  <servers>

        <server>

            <id>nexus-releases</id>

            <username>deployment</username>

            <password>123456</password>

        </server>

        <server>

            <id>nexus-snapshots</id>

            <username>deployment</username>

            <password>123456</password>

        </server>

 </servers>

然后在对应pom.xml中定义如下(与上面的id对应):

<distributionManagement>

    <repository>

        <id>nexus-releases</id>

        <name>Nexus Release Repository</name>

        <url>http://nexus.xxx.com:8081/nexus/content/repositories/releases/</url>

    </repository>

    <snapshotRepository>

        <id>nexus-snapshots</id>

        <name>Nexus Snapshot Repository</name>

        <url>http://nexus.xxx.com:8081/nexus/content/repositories/snapshots/</url>

    </snapshotRepository>

</distributionManagement>

 

镜像:

settings.xml配置如下:

<mirrors>

    <mirror>

        <id>planetmirror.com</id>

        <name>PlanetMirror Australia</name>

        <url>http://downloads.planetmirror.com/pub/maven2</url>

        <mirrorOf>central</mirrorOf>

    </mirror>

</mirrors>

注:id镜像唯一标识符,url镜像url,mirrorOf与中央仓库的id central一致。

 

代理:

settings.xml配置如下:

<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是否激活代理(当有多个代理时,使用第一个设置为true),host代理的主机,nonProxyHosts不被代理的地址。

 

Profiles:

只关心构建系统整体,含 activation、repositories、pluginRepositories、properties 元素

 

激活(Activation):

根据特定环境自动使用某些值

<profiles>

    <profile>

        <id>test</id>

        <activation>

            <activeByDefault>false</activeByDefault>

            <jdk>1.6</jdk>

            <os>

                <name>Windows 7</name>                

                <family>Windows</family>

                <arch>x86</arch>

                <version>5.1.2600</version>

            </os>

            <property>

                <name>hello</name>

                <value>world</value>

            </property>

            <file>

                <exists>D:/file2.properties</exists>

                <missing>D:/file1.properties</missing>

            </file>

        </activation>

        ...

    </profile>

</profiles>

注:id唯一标识符(这里可看成测试环境),activeByDefault为false表不自动激活,需要满足jdk、os、property、file(是否存在/不存在判断)四个条件才激活(四个条件均是可选)。

如jdk、os、file均符合执行以下则激活:

mvn compile –Dhello=world

 

属性(Properties):

如果profile被激活,里面设置的属性可在任何pom.xml用 ${user.install}访问:

<profile>

    ...

    <properties>

        <user.install>D:/test</user.install>

    </properties>

    ...

</profile>

 

仓库(Repositories):

  <repositories>

    <repository>

      <id>maven-net-cn</id>

      <name>Maven China Mirror</name>

      <url>http://maven.net.cn/content/groups/public/</url>

      <releases>

        <enabled>true</enabled>

      </releases>

      <snapshots>

        <enabled>false</enabled>

      </snapshots>

    </repository>

  </repositories>

  <pluginRepositories>

    <pluginRepository>

      <id>maven-net-cn</id>

      <name>Maven China Mirror</name>

      <url>http://maven.net.cn/content/groups/public/</url>

      <releases>

        <enabled>true</enabled>

      </releases>

      <snapshots>

        <enabled>false</enabled>

      </snapshots>    

    </pluginRepository>

  </pluginRepositories>

 

激活Profiles:

settings.xml中设置激活如下:

...

    <activeProfiles>

        <activeProfile>test</activeProfile>

    </activeProfiles>

</settings>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值