Settings配置介绍
1 servers标签介绍
如果有搭建自己公司的maven私服,公司内部会把自己的公司的公共jar包上传到maven私服中。 如果私服配置了上传权限,servers标签需要给出授权信息。
1.1 使用方法
1.在maven的工程中,pom中使用ditributionManagement标签私服地址。
<distributionManagement>
<repository>
<id>release-repository</id>
<name>Release Repository</name>
<url>http://www.myrepository.com/repositories/releases</url>
</repository>
<snapshotRepository>
<id>snapshot-repository</id>
<name>Snapshot Repository</name>
<url>http://www.myrepository.com/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
2.在maven的settings.xml中配置servers。
<servers>
<server>
<id>snapshot-repository</id>
<username>snapshot</username>
<password>123456</password>
</server>
<server>
<id>release-repository</id>
<username>release</username>
<password>123456</password>
</server>
</servers>
需要注意的是两处的id需要相互匹配。
帐号的权限都是私服配置的。上传到SNAPSHOT还是RELEASE是由项目的version决定的。
2 profile标签介绍
2.1 profile简介
profile可以让我们定义一系列的配置信息,然后指定其激活条件。这样我们就可以定义多个profile,然后每个profile对应不同的激活条件和配置信息,从而达到不同环境使用不同配置信息的效果。比如说,我们可以通过profile定义在jdk1.5以上使用一套配置信息,在jdk1.5以下使用另外一套配置信息;或者有时候我们可以通过操作系统的不同来使用不同的配置信息,比如windows下是一套信息,linux下又是另外一套信息,等等。具体的激活条件有哪些我在后文会讲到。
2.2 profile的定义位置
对于使用Maven3,我们可以有多个地方定义profile。定义的地方不同,它的作用范围也不同。
针对于特定项目的profile配置我们可以定义在该项目的pom.xml中。
针对于特定用户的profile配置,我们可以在用户的settings.xml文件中定义profile。该文件在用户家目录下的“.m2”目录下。
全局的profile配置。全局的profile是定义在Maven安装目录下的“conf/settings.xml”文件中的。
2.3 profile中能定义的信息
profile中能够定义的配置信息跟profile所处的位置是相关的。以下就分两种情况来讨论,一种是定义在settings.xml中,另一种是定义在pom.xml中。
2.3.1 profile定义在settings.xml中
当profile定义在settings.xml中时意味着该profile是全局的,它会对所有项目或者某一用户的所有项目都产生作用。因为它是全局的,所以在settings.xml中只能定义一些相对而言范围宽泛一点的配置信息,比如远程仓库等。而一些比较细致一点的需要根据项目的不同来定义的就需要定义在项目的pom.xml中。具体而言,能够定义在settings.xml中的信息有<repositories>、<pluginRepositories>和<properties>。定义在<properties>里面的键值对可以在pom.xml中使用。
2.3.2 profile定义在pom.xml中
定义在pom.xml中的profile可以定义更多的信息。主要有以下这些:
l <repositories>
l <pluginRepositories>
l <dependencies>
l <plugins>
l <properties>
l <dependencyManagement>
l <distributionManagement>