pom中节点如下分布
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
用于确定父项目的坐标。
<parent>
<groupId>com.learnProgroupId>
<artifactId>SIP-parentartifactId>
<relativePath>relativePath>
<version>0.0.1-SNAPSHOTversion>
parent>
有些maven项目会做成多模块的,这个标签用于指定当前项目所包含的所有模块。之后对这个项目进行的maven操作,会让所有子模块也进行相同操作。
<module>com-a</>
<module>com-b</>
<module>com-c</>
</>
用于定义pom常量
<properties>
<java.version>1.7java.version>
properties>
上面这个常量可以在pom文件的任意地方通过${java.version}来引用
项目相关依赖配置,如果在父项目写的依赖,会被子项目引用,一般父项目会将子项目公用的依赖引入(将在之后详细讲解)
<dependencies>
<dependency>
<groupId>junitgroupId>
<artifactId>junitartifactId>
<version>4.12version>
dependency>
dependencies>
这边依赖和中央仓库中的一致,就可以引入对应的jar
配置写法同dependencies
<dependencyManagement>
<dependencies>
.....
dependencies>
dependencyManagement>
在父模块中定义后,子模块不会直接使用对应依赖,但是在使用相同依赖的时候可以不加版本号:
父项目:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junitgroupId>
<artifactId>junitartifactId>
<version>4.12version>
<scope>testscope>
dependency>
dependencies>
dependencyManagement>
子项目:
<dependency>
<groupId>junitgroupId>
<artifactId>junitartifactId>
dependency>
这样的好处是,父项目统一了版本,而且子项目可以在需要的时候才引用对应的依赖
用于配置项目构建相关信息
<build>
<sourceDirectory/>
<scriptSourceDirectory/>
<testSourceDirectory/>
<outputDirectory/>
<testOutputDirectory/>
<extensions>
<extension>
<groupId/>
<artifactId/>
<version/>
extension>
extensions>
<defaultGoal/>
<resources>
<resource>
<targetPath/>
<filtering/>
<directory/>
<includes/>
<excludes/>
resource>
resources>
<testResources>
<testResource>
<targetPath/><filtering/><directory/><includes/><excludes/>
testResource>
testResources>
<directory/>
<finalName/>
<filters/>
<pluginManagement>
<plugins>
<plugin>
<groupId/>
<artifactId/>
<version/>
<extensions/>
<executions>
<execution>
<id/>
<phase/>
<goals/>
<inherited/>
<configuration/>
execution>
executions>
<dependencies>
<dependency>
......
dependency>
dependencies>
<inherited/>
<configuration/>
plugin>
plugins>
pluginManagement>
<plugins>
<plugin>
<groupId/><artifactId/><version/><extensions/>
<executions>
<execution>
<id/><phase/><goals/><inherited/><configuration/>
execution>
executions>
<dependencies>
<dependency>
......
dependency>
dependencies>
<goals/><inherited/><configuration/>
plugin>
plugins>
build>
该元素描述使用报表插件产生报表的规范。当用户执行“mvn site”,这些报表就会运行。 在页面导航栏能看到所有报表的链接。
<reporting>
<excludeDefaults/>
<outputDirectory/>
<plugins>
<plugin>
<groupId/>
<artifactId/>
<version/>
<inherited/>
<configuration/>
<reportSets>
<reportSet>
<id/>
<configuration/>
<inherited/>
<reports/>
reportSet>
reportSets>
plugin>
plugins>
reporting>
<license>
<name>...name>
<url>....url>
<distribution>repodistribution>
<comments>....comments>
license>
<developers>
<developer>
<id>....id>
<name>...name>
<email>...email>
<url>...<url/>
<roles>
<role>Java Devrole>
<role>Web UIrole>
roles>
<organization>sunorganization>
<organizationUrl>...organizationUrl>
<properties>
properties>
<timezone>-5timezone>
developer>
developers>
目的问题管理系统(Bugzilla, Jira, Scarab)的名称和URL
<issueManagement>
<system>Bugzillasystem>
<url>http://127.0.0.1/bugzilla/url>
issueManagement>
项目的持续集成信息
<ciManagement>
<system>continuumsystem>
<url>http://127.0.0.1:8080/continuumurl>
<notifiers>
<notifier>
<type>mailtype>
<sendOnError>truesendOnError>
<sendOnFailure>truesendOnFailure>
<sendOnSuccess>falsesendOnSuccess>
<sendOnWarning>falsesendOnWarning>
<address>[email protected]address>
<configuration>configuration>
notifier>
notifiers>
ciManagement>
项目相关邮件列表信息
<mailingLists>
<mailingList>
<name>User Listname>
<subscribe>[email protected]subscribe>
<unsubscribe>[email protected]unsubscribe>
<post>[email protected]post>
<archive>http://127.0.0.1/user/archive>
<otherArchives>
<otherArchive>http://base.google.com/base/1/127.0.0.1otherArchive>
otherArchives>
mailingList>
.....
mailingLists>
允许你配置你的代码库,供Maven web站点和其它插件使用
<scm>
<connection>scm:svn:http://127.0.0.1/svn/my-projectconnection>
<developerConnection>scm:svn:https://127.0.0.1/svn/my-projectdeveloperConnection>
<tag>HEADtag>
<url>http://127.0.0.1/websvn/my-projecturl>
scm>
项目构建的前提
<prerequisites>
<maven>2.0.6maven>
prerequisites>
依赖和扩展的远程仓库列表,同上篇文章,setting.xml配置中介绍的。
<repositories>
<repository>
<releases>
<enabled>falseenabled>
<updatePolicy>alwaysupdatePolicy>
<checksumPolicy>warnchecksumPolicy>
releases>
<snapshots>
<enabled>trueenabled>
<updatePolicy>neverupdatePolicy>
<checksumPolicy>failchecksumPolicy>
snapshots>
<id>codehausSnapshotsid>
<name>Codehaus Snapshotsname>
<url>http://snapshots.maven.codehaus.org/maven2url>
<layout>defaultlayout>
repository>
repositories>
<pluginRepositories>
...
pluginRepositories>
它管理的分布在整个构建过程生成的工件和支持文件
...
http://mojo.codehaus.org/my-project
deployed
指定Maven pom从远程下载控件到当前项目的位置和方式,如果snapshotRepository没有被定义则使用repository相关的配置
<distributionManagement>
<repository>
<uniqueVersion>falseuniqueVersion>
<id>corp1id>
<name>Corporate Repositoryname>
<url>scp://repo/maven2url>
<layout>defaultlayout>
repository>
<snapshotRepository>
<uniqueVersion>trueuniqueVersion>
<id>propSnapid>
<name>Propellors Snapshotsname>
<url>sftp://propellers.net/mavenurl>
<layout>legacylayout>
snapshotRepository>
...
distributionManagement>
多分布存储库,distributionManagement负责定义如何部署项目的网站和文档。
...
mojo.website
Mojo Website
scp://beaver.codehaus.org/home/projects/mojo/public_html/
...
重新部署-项目不是静态的,是活的。他们需要被搬到更合适的地方。如:当你的下个成功的开源项目移到Apache下,重命名为org.apache:my-project:1.0 对你项目更有好处。
...
org.apache
my-project
1.0
We have moved the Project under Apache
...
profile可以让我们定义一系列的配置信息(插件等),然后指定其激活条件
profile的相关配置可以参考上篇文章Maven实战(二)–setting.xml详解:
参考官方文档: http://maven.apache.org/pom.html