转载自 Maven的pom.xml文件详解------Environment Settings
Issue Management
使用的缺陷跟踪系统(Bugzilla,TestTrack,ClearQuest,等)信息,主要用于产生项目文档。
<issueManagement><system>Bugzilla</system><url>http://127.0.0.1/bugzilla/</url>
</issueManagement>
Continuous Integration Management
持续构建系统配置。
<ciManagement><system>continuum</system><url>http://127.0.0.1:8080/continuum</url><notifiers><notifier><type>mail</type><sendOnError>true</sendOnError><sendOnFailure>true</sendOnFailure><sendOnSuccess>false</sendOnSuccess><sendOnWarning>false</sendOnWarning><configuration><address>continuum@127.0.0.1</address></configuration></notifier></notifiers>
</ciManagement>
notifiers:定义当出现构建状态时需要通知的人,已经通知的方式。
Mailing Lists
定义了该项目需要保持联系的人员,主要是开发人员和用户的邮件列表。
<mailingLists><mailingList><name>User List</name><subscribe>user-subscribe@127.0.0.1</subscribe><unsubscribe>user-unsubscribe@127.0.0.1</unsubscribe><post>user@127.0.0.1</post><archive>http://127.0.0.1/user/</archive><otherArchives><otherArchive>http://base.google.com/base/1/127.0.0.1</otherArchive></otherArchives></mailingList>
</mailingLists>
1)subscribe、unsubscribe:执行对应行为指定的邮件地址。如为了订阅上面用户的,一个用户需要发送email到user-subscribe@127.0.0.1;
2)archive:已归档的邮件列表邮件的url,如果有镜像归档地址,则指定到otherArchives中;
3)post:post到邮件列表的邮件地址。
SCM
SCM:Software Configuration Management,也称作Source Code/Control Management简洁的成为version control。
这里是你存放版本管理信息到POM的地方
<scm><connection>scm:svn:http://127.0.0.1/svn/my-project</connection><developerConnection>scm:svn:https://127.0.0.1/svn/my-project</developerConnection><tag>HEAD</tag><url>http://127.0.0.1/websvn/my-project</url>
</scm>
1)connection:要求对源代码有读的权限,可以更新;developerConnection:要求对源代码有写的权限,可以提交代码;
Maven有另一个项目Maven SCM,提供公共的API,供SCM的插件实现。目前所有的SCM的插件可以在http://maven.apache.org/scm/scms-overview.html上找到;
2)tag:指定该项目所在的标签。HEAD是默认;
3)url:一个公共的可浏览的仓库。
Prerequisites
为了让该POM正确的执行所需要的先决条件,这里是你定义先决条件的地方。如果不满足这些先决条件,Maven将不会开始。目前只有maven的最小版本号一个先决条件。
<prerequisites><maven>2.0.6</maven>
</prerequisites>
Repositories
定义Maven的仓库地址,在Super POM中已经定义了Maven的默认仓库中心http://repo.maven.apache.org/maven2(见Super POM)。
<repositories><repository><releases><enabled>false</enabled><updatePolicy>always</updatePolicy><checksumPolicy>warn</checksumPolicy></releases><snapshots><enabled>true</enabled><updatePolicy>never</updatePolicy><checksumPolicy>fail</checksumPolicy></snapshots><id>codehausSnapshots</id><name>Codehaus Snapshots</name><url>http://snapshots.maven.codehaus.org/maven2</url><layout>default</layout></repository>
</repositories>
<pluginRepositories>...
</pluginRepositories>
1)releases、snapshots:针对组件的发布类型能干采取的策略(release或者snapshot);
2)enabled:true/false,仓库对于对应的类型是否激活;
3)updatePolicy:指定Maven尝试更新的频率,Maven将比较本地POM的时间戳(存储在仓库的maven-metadata文件中)和远端POM的时间戳,选择为:always,daily(默认),interval:X(X为整数,单位分钟)或者never;
4)checksumPolicy:当Maven部署文件到仓库时,它也部署了对应的校验和文件。你可以选择ignore、fail或者warn来响应当文件丢失或者不正确后的操作;
5)layout:default/legacy,Maven 2和Maven 3都是用default layout。
pluginRepositories的配置方式和repositories一致。
Distribution Management
管理build生成的组件和资源文件和分发。
基本属性
<distributionManagement>...<downloadUrl>http://mojo.codehaus.org/my-project</downloadUrl><status>deployed</status>
</distributionManagement>
downloadUrl:另一个POM配置用于获取该POM的组件的仓库的url;
status:这个值不能手动配置,当该组件上传到仓库时,Maven将设置这个项目的状态,它的有效值为:
none:没有特殊状态,默认;
converted:仓库的管理人员从一个对Maven 2来说更早的版本转换到这个POM;
partner:这个组件有被同步到一个合作仓库;
deployed:最通用的状态,这个组件从Maven2或者Maven2部署;
verified:这个项目被查证了,应该被终止。
Repository
distributionManagement通过repository定义当组件部署时,项目可以从哪里(和怎么)获取远端仓库。
<distributionManagement><repository><uniqueVersion>false</uniqueVersion><id>corp1</id><name>Corporate Repository</name><url>scp://repo/maven2</url><layout>default</layout></repository><snapshotRepository><uniqueVersion>true</uniqueVersion><id>propSnap</id><name>Propellors Snapshots</name><url>sftp://propellers.net/maven</url><layout>legacy</layout></snapshotRepository>...
</distributionManagement>
id:仓库的唯一标识;
name:人类可读的名称;
uniqueVersion:true/false,表示部署到该仓库的组件是否应该获取一个唯一产生的版本号,并用这个版本号作为地址的一部分;
url:指定用于传送构建成的组件(包括POM文件和校验和数据)到仓库的网络地址和传输协议,是Repository的核心;
layout:default/legacy,同project下的repository 元素。
Site Distribution
比起分发到仓库,distributionManagement更多的运用是定义怎么部署项目的站点和文档。
<distributionManagement>...<site><id>mojo.website</id><name>Mojo Website</name><url>scp://beaver.codehaus.org/home/projects/mojo/public_html/</url></site>...
</distributionManagement>
Relocation
<distributionManagement>...<relocation><groupId>org.apache</groupId><artifactId>my-project</artifactId><version>1.0</version><message>We have moved the Project under Apache</message></relocation>...
</distributionManagement>
项目在发展的过程中,可能被迫转移到其它更适合的地方。relocation用于给项目的用户指名该项目被重命名为什么(例如上面,项目被重命名到org.apache:my-project:1.0),除此之外,它还提供一个项目转移的解释。
Profiles
POM 4.0的一个新特征是改变项目被构建的环境的settings的能力。
<profiles><profile><id>test</id><activation>...</activation><build>...</build><modules>...</modules><repositories>...</repositories><pluginRepositories>...</pluginRepositories><dependencies>...</dependencies><reporting>...</reporting><dependencyManagement>...</dependencyManagement><distributionManagement>...</distributionManagement></profile>
</profiles>
Activation
Activation是profile的关键。一个profile的威力来自于在当前的环境下修改基本POM的能力。
<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>sparrow-type</name><value>African</value></property><file><exists>${basedir}/file2.properties</exists><missing>${basedir}/file1.properties</missing></file></activation>...</profile>
</profiles>
jdk:如果jdk版本号匹配被给的前缀,则profile被激活,例如:1.5.0_06将匹配上面的配置; os:在哪些操作系统下profile被激活; property:profile将激活,如果Maven探测到一个对应的name=value对的property。 file:一个通过file的existence指定的文件名可以激活profile。