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>