maven配置详解

setting.xml配置

setting.xml 概览

<?xml version="1.0" encoding="UTF-8"?>
<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
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository/>
<interactiveMode/>
<offline/>
<pluginGroups/>
<servers/>
<mirrors/>
<proxies/>
<profiles/>
<activeProfiles/>
</settings>

localRepository(Maven仓库) 

      

<localRepository>E:\WorkSpace\IDEs\Maven\MavenRepository</localRepository>

interactiveMode 

interactiveMode 用于决定maven是否在需要输出的时候提示你,默认true。如果是false,它将使用合理的默认值,或者基于一些设置。(使用命令行输出时是否有提示)

offline

决定maven是否在构建的时候进行网络传输。 默认false,表示联网状态,true为取消联网。 在某些情况下设置为true是很有用的,比如jar无法从网上下载等。(不使用镜像,只使用本地仓库)

pluginGroups

Maven组件,默认使用的是 org.apache.maven.plugins所有组件。在Maven 管理项目的生命周期时会用到plugin。一下为Maven常用的plugins(打包,编译,之类的)

proxies

此项用于设置http代理 有时候由于安全问题,需要配置http代理,通过代理服务才能正常访问外部仓库下载资源可以ping http://repo1.maven.org来访问中央仓库 telnet 218.14.227.197 3128 来查看代理地址以及端口是否畅通

<proxies>
<proxy>
<id>optional</id>
<active>true</active>
<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>

  • id:proxy的唯一标识,用来区别proxy元素。
  • active:表示是否激活代理,如果配置多个,默认是第一个生效
  • username,password:提供连接代理服务器时的认证。
  • host,port:主机地址,端口号
  • nonProxyHosts:用来表示哪些主机名不需要代理,可以用|来分 割多个,此外也支持通配符,
  • 如:*.http://goole.com表示所有以http://goole.com结尾的都不需要通过代理
  • Default:
  • Customized:使用的不同的protocol 获取资源,可以配置多个proxy,顺序加载读取。

servers

这是一个认证配置的列表,根据系统中使用的server-id控制。认证配置在maven连接到远程服务时使用。

<servers>
| Specifies the authentication information to use when connecting to a particular server, identified by
| a unique name within the system (referred to by the 'id' attribute below).
|
| NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
|       used together.
|
<server>
<id>deploymentRepo</id>
<username>repouser</username>
<password>repopwd</password>
</server>
<!-- Another sample, using keys to authenticate.
<server>
<id>siteServer</id>
<privateKey>/path/to/private/key</privateKey>
<passphrase>optional; leave empty if not used.</passphrase>
</server>
</servers>

 可以配置多个Server 顺序读取

mirrors

<mirrors>
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>*,!jeecg,!jeecg-snapshots</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
<mirrors>
</mirrors>

profiles

  1. settings.xml中时意味着该profile是全局的,所以只能配置范围宽泛一点配置信息,比如远程仓库等。而一些比较细致一点的需要定义在项目的pom.xml中。
  2. profile可以让我们定义一系列的配置信息,然后指定其激活条件。 根据每个profile对应不同的激活条件和配置信息,从而达到不同环境使用不同配置。
  3. 例子:通过profile定义jdk1.5以上使用一套配置,jdk1.5以下使用另外一套配置;或者通过操作系统来使用不同的配置信息。
  4. settings.xml中的信息有repositories、pluginRepositories和properties。定义在properties的值可以在pom.xml中使用。
  5. <profiles>
    <profile>
    <id>test</id>
    <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>
    </profile>
    </profiles>
  • jdk:检测到对应jdk版本就激活
  • os:针对不同操作系统(通常都不需要配置)
  • property:当maven检测到property(pom中如${name}这样的)profile将被激活(通常都不需要配置)
  • file:如果存在文件,激活,不存在文件激活(通常都不需要配置)

通过以下命令查看哪些profile将生效

- mvn help:active-profiles

activeProfiles

每个activeProfile元素对应一个profile id的值,任何profile id被定义到activeProfile的profile将被激活。

  1. <activeProfiles>
  2. <activeProfile>alwaysActiveProfile</activeProfile>
  3. <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  4. </activeProfiles>

mavne的release和snapshot的区别

release是发布版本,一般很稳定,不会变动

snapshot是快照版本,不稳定,需要高频更新,maven每次加载的时候都会重新加载一遍快照版本

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值