maven核心---pom.xml详解

转:http://www.cnblogs.com/qq78292959/p/3711501.html

      http://blog.csdn.net/odeviloo/article/details/52050277

什么是pom?
    pom作为项目对象模型。通过xml表示maven项目,使用pom.xml来实现。主要描述了项目:包括配置文件;开发者需要遵循的规则,缺陷管理系统,组织和licenses,项目的url,项目的依赖性,以及其他所有的项目相关因素。

 

 

快速察看:
<project>
  <modelVersion>4.0.0</modelVersion>
<!--maven2.0必须是这样写,现在是maven2唯一支持的版本-->
  <!-- 基础设置 -->
  <groupId>...</groupId>
  <artifactId>...</artifactId>
  <version>...</version>
  <packaging>...</packaging>

  <name>...</name>

  <url>...</url>
  <dependencies>...</dependencies>
  <parent>...</parent>
  <dependencyManagement>...</dependencyManagement>
  <modules>...</modules>
  <properties>...</properties>

  <!--构建设置 -->
  <build>...</build>
  <reporting>...</reporting>

  <!-- 更多项目信息 -->
  <name>...</name>
  <description>...</description>
  <url>...</url>
  <inceptionYear>...</inceptionYear>
  <licenses>...</licenses>
  <organization>...</organization>
  <developers>...</developers>
  <contributors>...</contributors>

  <!-- 环境设置-->
  <issueManagement>...</issueManagement>
  <ciManagement>...</ciManagement>
  <mailingLists>...</mailingLists> 
  <scm>...</scm>
  <prerequisites>...</prerequisites>
  <repositories>...</repositories>
  <pluginRepositories>...</pluginRepositories>
  <distributionManagement>...</distributionManagement>
  <profiles>...</profiles>
</project>

 

基本内容:

POM包括了所有的项目信息

groupId:项目或者组织的唯一标志,并且配置时生成路径也是由此生成,如org.myproject.mojo生成的相对路径为:/org/myproject/mojo

artifactId:项目的通用名称

version:项目的版本

packaging:打包机制,如pom,jar,maven-plugin,ejb,war,ear,rar,par

name:用户描述项目的名称,无关紧要的东西,可选

url:应该是只是写明开发团队的网站,无关紧要,可选

classifer:分类

其中groupId,artifactId,version,packaging这四项组成了项目的唯一坐标。一般情况下,前面三项就可以组成项目的唯一坐标了。

 

POM关系:主要为依赖,继承,合成

依赖关系:

<dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.0</version>
      <type>jar</type>
      <scope>test</scope>
      <optional>true</optional>
    </dependency>

 

    <dependency>

        <groupId>com.alibaba.china.shared</groupId>

        <artifactId>alibaba.apollo.webx</artifactId>

        <version>2.5.0</version>

        <exclusions>

          <exclusion>

            <artifactId>org.slf4j.slf4j-api</artifactId>

            <groupId>com.alibaba.external</groupId>

          </exclusion>

          ....

        </exclusions>

......

</dependencies>

其中groupId, artifactId, version这三个组合标示依赖的具体工程,而且 这个依赖工程必需是maven中心包管理范围内的,如果碰上非开源包,maven支持不了这个包,那么则有有三种 方法处理:

1.本地安装这个插件install plugin

例如:mvn install:intall-file -Dfile=non-maven-proj.jar -DgroupId=som.group -DartifactId=non-maven-proj -Dversion=1

2.创建自己的repositories并且部署这个包,使用类似上面的deploy:deploy-file命令,

3.设置scope为system,并且指定系统路径。

 

dependency里属性介绍:

type:默认为jar类型,常用的类型有:jar,ejb-client,test-jar...,可设置plugins中的extensions值为true后在增加 新的类型,

scope:是用来指定当前包的依赖范围,maven的依赖范围

optional:设置指依赖是否可选,默认为false,即子项目默认都继承,为true,则子项目必需显示的引入,与dependencyManagement里定义的依赖类似 。

exclusions:如果X需要A,A包含B依赖,那么X可以声明不要B依赖,只要在exclusions中声明exclusion.

exclusion:是将B从依赖树中删除,如上配置,alibaba.apollo.webx不想使用com.alibaba.external  ,但是alibaba.apollo.webx是集成了com.alibaba.external,r所以就需要排除掉.

 

如果一个工程是parent或者aggregation(即mutil-module的)的,那么必须在packing赋值为pom,child工程从parent继承的包括:dependencies,developers,contributors,plugin lists,reports lists,plugin execution with matching ids,plugin configuration

parent的使用方法如下:

<parent> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>my-parent</artifactId> 
    <version>2.0</version> 
    <relativePath>../my-parent</relativePath> 
  </parent>

relativePath是可选的,maven会首先搜索这个地址,在搜索本地远程repositories之前.

 

dependencyManagement:是用于帮助管理chidren的dependencies的。例如如果parent使用dependencyManagement定义了一个dependencyon junit:junit4.0,那么 它的children就可以只引用 groupId和artifactId,而version就可以通过parent来设置,这样的好处就是可以集中管理 依赖的详情

 

modules:对于多模块的project,outer-module没有必需考虑inner-module的dependencies,当列出modules的时候,modules的顺序是不重要的,因为maven会自动根据依赖关系来拓扑排序,

modules例子如下 :

<module>my-project</module>

<module>other-project</module>

 

properties:是为pom定义一些常量,在pom中的其它地方可以直接引用。

定义方式如下:

 

<properties>

      <file.encoding>UTF-8</file_encoding>

      <java.source.version>1.5</java_source_version>

      <java.target.version>1.5</java_target_version>

</properties>

使用方式 如下 :

${file.encoding}

 

还可以使用project.xx引用pom里定义的其它属性:如$(project.version} 

 

build设置:

defaultGoal:默认的目标,必须跟命令行上的参数相同,如:jar:jar,或者与时期parse相同,例如install

directory:指定build target目标的目录,默认为$(basedir}/target,即项目根目录下的target

finalName:指定去掉后缀的工程名字,例如:默认为${artifactId}-${version}

filters:用于定义指定filter属性的位置,例如filter元素赋值filters/filter1.properties,那么这个文件里面就可以定义name=value对,这个name=value对的值就可以在工程pom中通过${name}引用,默认的filter目录是${basedir}/src/main/fiters/

resources:描述工程中资源的位置 

 

<resource> 
        <targetPath>META-INF/plexus</targetPath> 
        <filtering>false</filtering> 
        <directory>${basedir}/src/main/plexus</directory> 
        <includes> 
          <include>configuration.xml</include> 
        </includes> 
        <excludes> 
          <exclude>**/*.properties</exclude> 
        </excludes> 
      </resource>

 

targetPath:指定build资源到哪个目录,默认是base directory

filtering:指定是否将filter文件(即上面说的filters里定义的*.property文件)的变量值在这个resource文件有效,例如上面就指定那些变量值在configuration文件无效。

directory:指定属性文件的目录,build的过程需要找到它,并且将其放到targetPath下,默认的directory是${basedir}/src/main/resources

includes:指定包含文件的patterns,符合样式并且在directory目录下的文件将会包含进project的资源文件。

excludes:指定不包含在内的patterns,如果inclues与excludes有冲突,那么excludes胜利,那些符合冲突的样式的文件是不会包含进来的。

testResources:这个模块包含测试资源元素,其内容定义与resources类似,不同的一点是默认的测试资源路径是${basedir}/src/test/resources,测试资源是不部署的。

 

plugins配置:

<plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-jar-plugin</artifactId> 
        <version>2.0</version> 
        <extensions>false</extensions> 
        <inherited>true</inherited> 
        <configuration> 
          <classifier>test</classifier> 
        </configuration> 
        <dependencies>...</dependencies> 
        <executions>...</executions> 
      </plugin>

extensions:true or false, 决定是否要load这个plugin的extensions,默认为true.

inherited:是否让子pom继承,ture or false 默认为true.

configuration:通常用于私有不开源的plugin,不能够详细了解plugin的内部工作原理,但使plugin满足的properties

dependencies:与pom基础的dependencies的结构和功能都相同,只是plugin的dependencies用于plugin,而pom的denpendencies用于项目本身。在plugin的dependencies主要用于改变plugin原来的dependencies,例如排除一些用不到的dependency或者修改dependency的版本等,详细请看pom的denpendencies.

executions:plugin也有很多个目标,每个目标具有不同的配置,executions就是设定plugin的目标,

<execution> 
            <id>echodir</id> 
            <goals> 
              <goal>run</goal> 
            </goals> 
            <phase>verify</phase> 
            <inherited>false</inherited> 
            <configuration> 
              <tasks> 
                <echo>Build Dir: ${project.build.directory}</echo> 
              </tasks> 
            </configuration> 
          </execution> 

id:标识符

goals:里面列出一系列的goals元素,例如上面的run goal

phase:声明goals执行的时期,例如:verify

inherited:是否传递execution到子pom里。

configuration:设置execution下列表的goals的设置,而不是plugin所有的goals的设置

 

pluginManagement配置:

pluginManagement的作用类似于denpendencyManagement,只是denpendencyManagement是用于管理项目jar包依赖,pluginManagement是用于管理plugin。与pom build里的plugins区别是,这里的plugin是列出来,然后让子pom来决定是否引用。

例如:

<pluginManagement> 

      <plugins> 
        <plugin> 
          <groupId>org.apache.maven.plugins</groupId> 
          <artifactId>maven-jar-plugin</artifactId> 
          <version>2.2</version> 
          <executions> 
            <execution> 
              <id>pre-process-classes</id> 
              <phase>compile</phase> 
              <goals> 
                <goal>jar</goal> 
              </goals> 
              <configuration> 
                <classifier>pre-process</classifier> 
              </configuration> 
            </execution> 
          </executions> 
        </plugin> 
      </plugins> 
    </pluginManagement> 
子pom引用方法: 
在pom的build里的plugins引用: 
    <plugins> 
      <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-jar-plugin</artifactId> 
      </plugin> 
    </plugins>

 

build里的directories:

 

<sourceDirectory>${basedir}/src/main/java</sourceDirectory> 
    <scriptSourceDirectory>${basedir}/src/main/scripts</scriptSourceDirectory> 
    <testSourceDirectory>${basedir}/src/test/java</testSourceDirectory> 
    <outputDirectory>${basedir}/target/classes</outputDirectory> 
    <testOutputDirectory>${basedir}/target/test-classes</testOutputDirectory>

这几个元素只在parent build element里面定义,他们设置多种路径结构,他们并不在profile里,所以不能通过profile来修改

 

build 里面的Extensions: 
它们是一系列build过程中要使用的产品,他们会包含在running bulid‘s classpath里面。他们可以开启extensions,也可以通过提供条件来激活plugins。简单来讲,extensions是在build过程被激活的产品 
    <extensions> 
      <extension> 
        <groupId>org.apache.maven.wagon</groupId> 
        <artifactId>wagon-ftp</artifactId> 
        <version>1.0-alpha-3</version> 
      </extension> 
    </extensions> 

 

reporting设置:

reporting包含site生成阶段的一些元素,某些maven plugin可以生成reports并且在reporting下配置。例如javadoc,maven site等,在reporting下配置的report plugin的方法与build几乎一样,最不同的是build的plugin goals在executions下设置,而reporting的configures goals在reporttest。

excludeDefaults:是否排除site generator默认产生的reports

outputDirectory,默认的dir变成:${basedir}/target/site

report sets:设置execution goals,相当于build里面的executions,不同的是不能够bind a report to another phase,只能够是site

<reporting> 
    <plugins> 
      <plugin> 
        ... 
        <reportSets> 
          <reportSet> 
            <id>sunlink</id> 
            <reports> 
              <report>javadoc</report> 
            </reports> 
            <inherited>true</inherited> 
            <configuration> 
              <links> 
                <link>http://java.sun.com/j2se/1.5.0/docs/api/</link> 
              </links> 
            </configuration> 
          </reportSet> 
        </reportSets> 
      </plugin> 
    </plugins> 
  </reporting> 
reporting里面的厄reportSets和build里面的executions的作用都是控制pom的不同粒度去控制build的过程,我们不单要配置plugins,还要配置那些plugins单独的goals。

 

更多项目信息:

name:项目除了artifactId外,可以定义多个名称
description: 项目描述
url: 项目url
inceptionYear:创始年份

 

Licenses
<licenses>
  <license>
    <name>Apache 2</name>
    <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
    <distribution>repo</distribution>
    <comments>A business-friendly OSS license</comments>
  </license>
</licenses>

列出本工程直接的licenses,而不要列出dependencies的licenses

 

配置组织信息:
  <organization>
    <name>Codehaus Mojo</name>
    <url>http://mojo.codehaus.org</url>
  </organization>

 

很多工程都受到某些组织运行,这里设置基本信息

 

配置开发者信息:

例如:一个开发者可以有多个roles,properties是 
<developers>
    <developer>
      <id>eric</id>
      <name>Eric</name>
      <email>eredmond@codehaus.org</email>
      <url>http://eric.propellors.net</url>
      <organization>Codehaus</organization>
      <organizationUrl>http://mojo.codehaus.org</organizationUrl>
      <roles>
        <role>architect</role>
        <role>developer</role>
      </roles>
      <timezone>-6</timezone>
      <properties>
        <picUrl>http://tinyurl.com/prv4t</picUrl>
      </properties>
    </developer>
  </developers>

 

环境设置:

issueManagement:bug跟踪管理系统,定义defect tracking system缺陷跟踪系统,比如有(bugzilla,testtrack,clearquest等).

例如:

  <issueManagement> 
    <system>Bugzilla</system> 
    <url>http://127.0.0.1/bugzilla/</url> 
  </issueManagement> 

 

仓库:

Repositories:pom里面的仓库与setting.xml里的仓库功能是一样的。主要的区别在于,pom里的仓库是个性化的。比如一家大公司里的setting文件是公用 的,所有项目都用一个setting文件,但各个子项目却会引用不同的第三方库,所以就需要在pom里设置自己需要的仓库地址。

repositories:要成为maven2的repository artifact,必须具有pom文件在$BASE_REPO/groupId/artifactId/version/artifactId-version.pom 
BASE_REPO可以是本地,也可以是远程的。repository元素就是声明那些去查找的repositories 
默认的central Maven repository在http://repo1.maven.org/maven2/

<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> 

release和snapshots:是artifact的两种policies,pom可以选择那种政策有效。 
enable:本别指定两种类型是否可用,true or false 
updatePolicy:说明更新发生的频率always 或者 never 或者 daily(默认的)或者 interval:X(X是分钟数) 

checksumPolicy:当Maven的部署文件到仓库中,它也部署了相应的校验和文件。您可以选择忽略,失败,或缺少或不正确的校验和警告。

layout:maven1.x与maven2有不同的layout,所以可以声明为default或者是legacy(遗留方式maven1.x)。

 

插件仓库:

pluginRepositories:与Repositories具有类似的结构,只是Repositories是dependencies的home,而这个是plugins 的home。

 

分发管理:

distributionManagement :管理distribution和supporting files。 

downloadUrl:是其他项目为了抓取本项目的pom’s artifact而指定的url,就是说告诉pom upload的地址也就是别人可以下载的地址。 
status:这里的状态不要受到我们的设置,maven会自动设置project的状态,有效的值:none:没有声明状态,pom默认的;converted:本project是管理员从原先的maven版本convert到maven2的;partner:以前叫做synched,意思是与partner repository已经进行了同步;deployed:至今为止最经常的状态,意思是制品是从maven2 instance部署的,人工在命令行deploy的就会得到这个;verified:本制品已经经过验证,也就是已经定下来了最终版。 
repository:声明deploy过程中current project会如何变成repository,说明部署到repository的信息。 
    <repository> 
      <uniqueVersion>false</uniqueVersion> 
      <id>corp1</id> 
      <name>Corporate Repository</name> 
      <url>scp://repo1/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> 
id, name::唯一性的id,和可读性的name 
uniqueVersion:指定是否产生一个唯一性的version number还是使用address里的其中version部分。true or false 
url:说明location和transport protocol 
layout:default或者legacy

 

profiles:pom4.0的一个新特性就是具有根据environment来修改设置的能力

它包含可选的activation(profile的触发器)和一系列的changes。例如test过程可能会指向不同的数据库(相对最终的deployment)或者不同的dependencies或者不同的repositories,并且是根据不同的JDK来改变的。那么结构如下: 

  <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: 
触发这个profile的条件配置如下例:(只需要其中一个成立就可以激活profile,如果第一个条件满足了,那么后面就不会在进行匹配。 
    <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的方法有多个:setting文件的activeProfile元素明确指定激活的profile的ID,在命令行上明确激活Profile用-P flag 参数 

查看某个build会激活的profile列表可以用:mvn help:active-profiles 

======================================================================================================

1.概述

pom中节点如下分布

<project xmlns="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">
    <modelVersion>4.0.0</modelVersion>

    <!-- 基本配置 -->
    <groupId>...</groupId>
    <artifactId>...</artifactId>
    <version>...</version>
    <packaging>...</packaging>


    <!-- 依赖配置 -->
    <dependencies>...</dependencies>
    <parent>...</parent>
    <dependencyManagement>...</dependencyManagement>
    <modules>...</modules>
    <properties>...</properties>

    <!-- 构建配置 -->
    <build>...</build>
    <reporting>...</reporting>

    <!-- 项目信息 -->
    <name>...</name>
    <description>...</description>
    <url>...</url>
    <inceptionYear>...</inceptionYear>
    <licenses>...</licenses>
    <organization>...</organization>
    <developers>...</developers>
    <contributors>...</contributors>

    <!-- 环境设置 -->
    <issueManagement>...</issueManagement>
    <ciManagement>...</ciManagement>
    <mailingLists>...</mailingLists>
    <scm>...</scm>
    <prerequisites>...</prerequisites>
    <repositories>...</repositories>
    <pluginRepositories>...</pluginRepositories>
    <distributionManagement>...</distributionManagement>
    <profiles>...</profiles>
</project>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45

2.基本配置

  • modelVersion:pom模型版本,maven2和3只能为4.0.0
  • groupId:组ID,maven用于定位
  • artifactId:在组中的唯一ID用于定位
  • version:项目版本
  • packaging:项目打包方式,有以下值:pom, jar, maven-plugin, ejb, war, ear, rar, par

3.依赖配置

parent

用于确定父项目的坐标。

<parent>
    <groupId>com.learnPro</groupId>
    <artifactId>SIP-parent</artifactId>
    <relativePath></relativePath>
    <version>0.0.1-SNAPSHOT</version>
</parent>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • groupId:父项目的构件标识符
  • artifactId:父项目的唯一标识符
  • relativePath:Maven首先在当前项目的找父项目的pom,然后在文件系统的这个位置(relativePath),然后在本地仓库,再在远程仓库找。
  • version:父项目的版本

modules

有些maven项目会做成多模块的,这个标签用于指定当前项目所包含的所有模块。之后对这个项目进行的maven操作,会让所有子模块也进行相同操作。

<modules>
   <module>com-a</>
   <module>com-b</>
   <module>com-c</>
</>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5

properties

用于定义pom常量

<properties>
    <java.version>1.7</java.version>
</properties>
 
 
  • 1
  • 2
  • 3

上面这个常量可以在pom文件的任意地方通过${java.version}来引用

dependencies

项目相关依赖配置,如果在父项目写的依赖,会被子项目引用,一般父项目会将子项目公用的依赖引入(将在之后详细讲解)

<dependencies>
    <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
    </dependency>
</dependencies>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

这边依赖和中央仓库中的一致,就可以引入对应的jar

dependencyManagement

配置写法同dependencies

<dependencyManagement>
    <dependencies>
    .....
    </dependencies>
</dependencyManagement>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5

在父模块中定义后,子模块不会直接使用对应依赖,但是在使用相同依赖的时候可以不加版本号:

父项目:
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

子项目:

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
</dependency>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

这样的好处是,父项目统一了版本,而且子项目可以在需要的时候才引用对应的依赖

4.构建配置

build

用于配置项目构建相关信息

<build>    
    <!--该元素设置了项目源码目录,当构建项目的时候,构建系统会编译目录里的源码。该路径是相对于pom.xml的相对路径。-->    
    <sourceDirectory/>    
    <!--该元素设置了项目脚本源码目录,该目录和源码目录不同:绝大多数情况下,该目录下的内容 会被拷贝到输出目录(因为脚本是被解释的,而不是被编译的)。-->    
  <scriptSourceDirectory/>    
  <!--该元素设置了项目单元测试使用的源码目录,当测试项目的时候,构建系统会编译目录里的源码。该路径是相对于pom.xml的相对路径。-->    
  <testSourceDirectory/>    
  <!--被编译过的应用程序class文件存放的目录。-->    
  <outputDirectory/>    
  <!--被编译过的测试class文件存放的目录。-->    
  <testOutputDirectory/>    
  <!--使用来自该项目的一系列构建扩展-->    
  <extensions>    
   <!--描述使用到的构建扩展。-->    
   <extension>    
    <!--构建扩展的groupId-->    
    <groupId/>    
    <!--构建扩展的artifactId-->    
    <artifactId/>    
    <!--构建扩展的版本-->    
    <version/>    
   </extension>    
  </extensions>    
  <!--当项目没有规定目标(Maven2 叫做阶段)时的默认值-->    
  <defaultGoal/>    
  <!--这个元素描述了项目相关的所有资源路径列表,例如和项目相关的属性文件,这些资源被包含在最终的打包文件里。-->    
  <resources>    
   <!--这个元素描述了项目相关或测试相关的所有资源路径-->    
   <resource>    
    <!-- 描述了资源的目标路径。该路径相对target/classes目录(例如${project.build.outputDirectory})。举个例 子,如果你想资源在特定的包里(org.apache.maven.messages),你就必须该元素设置为org/apache/maven /messages。然而,如果你只是想把资源放到源码目录结构里,就不需要该配置。-->    
    <targetPath/>    
    <!--是否使用参数值代替参数名。参数值取自properties元素或者文件里配置的属性,文件在filters元素里列出。-->    
    <filtering/>    
    <!--描述存放资源的目录,该路径相对POM路径-->    
    <directory/>    
    <!--包含的模式列表,例如**/*.xml.-->    
    <includes/>    
    <!--排除的模式列表,例如**/*.xml-->    
    <excludes/>    
   </resource>    
  </resources>    
  <!--这个元素描述了单元测试相关的所有资源路径,例如和单元测试相关的属性文件。-->    
  <testResources>    
   <!--这个元素描述了测试相关的所有资源路径,参见build/resources/resource元素的说明-->    
   <testResource>    
    <targetPath/><filtering/><directory/><includes/><excludes/>    
   </testResource>    
  </testResources>    
  <!--构建产生的所有文件存放的目录-->    
  <directory/>    
  <!--产生的构件的文件名,默认值是${artifactId}-${version}。-->    
  <finalName/>    
  <!--当filtering开关打开时,使用到的过滤器属性文件列表-->    
  <filters/>    
  <!--子项目可以引用的默认插件信息。该插件配置项直到被引用时才会被解析或绑定到生命周期。给定插件的任何本地配置都会覆盖这里的配置-->    
  <pluginManagement>    
   <!--使用的插件列表 。-->    
   <plugins>    
    <!--plugin元素包含描述插件所需要的信息。-->    
    <plugin>    
     <!--插件在仓库里的group ID-->    
     <groupId/>    
     <!--插件在仓库里的artifact ID-->    
     <artifactId/>    
     <!--被使用的插件的版本(或版本范围)-->    
     <version/>    
     <!--是否从该插件下载Maven扩展(例如打包和类型处理器),由于性能原因,只有在真需要下载时,该元素才被设置成enabled。-->    
     <extensions/>    
     <!--在构建生命周期中执行一组目标的配置。每个目标可能有不同的配置。-->    
     <executions>    
      <!--execution元素包含了插件执行需要的信息-->    
      <execution>    
       <!--执行目标的标识符,用于标识构建过程中的目标,或者匹配继承过程中需要合并的执行目标-->    
       <id/>    
       <!--绑定了目标的构建生命周期阶段,如果省略,目标会被绑定到源数据里配置的默认阶段-->    
       <phase/>    
       <!--配置的执行目标-->    
       <goals/>    
       <!--配置是否被传播到子POM-->    
       <inherited/>    
       <!--作为DOM对象的配置-->    
       <configuration/>    
      </execution>    
     </executions>    
     <!--项目引入插件所需要的额外依赖-->    
     <dependencies>    
      <!--参见dependencies/dependency元素-->    
      <dependency>    
       ......    
      </dependency>    
     </dependencies>         
     <!--任何配置是否被传播到子项目-->    
     <inherited/>    
     <!--作为DOM对象的配置-->    
     <configuration/>    
    </plugin>    
   </plugins>    
  </pluginManagement>    
  <!--使用的插件列表-->    
  <plugins>    
   <!--参见build/pluginManagement/plugins/plugin元素-->    
   <plugin>    
    <groupId/><artifactId/><version/><extensions/>    
    <executions>    
     <execution>    
      <id/><phase/><goals/><inherited/><configuration/>    
     </execution>    
    </executions>    
    <dependencies>    
     <!--参见dependencies/dependency元素-->    
     <dependency>    
      ......    
     </dependency>    
    </dependencies>    
    <goals/><inherited/><configuration/>    
   </plugin>    
  </plugins>    
 </build>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118

reporting

该元素描述使用报表插件产生报表的规范。当用户执行“mvn site”,这些报表就会运行。 在页面导航栏能看到所有报表的链接。

<reporting>    
  <!--true,则,网站不包括默认的报表。这包括“项目信息”菜单中的报表。-->    
  <excludeDefaults/>    
  <!--所有产生的报表存放到哪里。默认值是${project.build.directory}/site。-->    
  <outputDirectory/>    
  <!--使用的报表插件和他们的配置。-->    
  <plugins>    
   <!--plugin元素包含描述报表插件需要的信息-->    
   <plugin>    
    <!--报表插件在仓库里的group ID-->    
    <groupId/>    
    <!--报表插件在仓库里的artifact ID-->    
    <artifactId/>    
    <!--被使用的报表插件的版本(或版本范围)-->    
    <version/>    
    <!--任何配置是否被传播到子项目-->    
    <inherited/>    
    <!--报表插件的配置-->    
    <configuration/>    
    <!--一组报表的多重规范,每个规范可能有不同的配置。一个规范(报表集)对应一个执行目标 。例如,有1,2,3,4,5,6,7,8,9个报表。1,2,5构成A报表集,对应一个执行目标。2,5,8构成B报表集,对应另一个执行目标-->    
    <reportSets>    
     <!--表示报表的一个集合,以及产生该集合的配置-->    
     <reportSet>    
      <!--报表集合的唯一标识符,POM继承时用到-->    
      <id/>    
      <!--产生报表集合时,被使用的报表的配置-->    
      <configuration/>    
      <!--配置是否被继承到子POMs-->    
      <inherited/>    
      <!--这个集合里使用到哪些报表-->    
      <reports/>    
     </reportSet>    
    </reportSets>    
   </plugin>    
  </plugins>    
 </reporting>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36

5.项目信息

  • name:给用户提供更为友好的项目名
  • description:项目描述,maven文档中保存
  • url:主页的URL,maven文档中保存
  • inceptionYear:项目创建年份,4位数字。当产生版权信息时需要使用这个值
  • licenses:该元素描述了项目所有License列表。 应该只列出该项目的license列表,不要列出依赖项目的 license列表。如果列出多个license,用户可以选择它们中的一个而不是接受所有license。(如下)
<license>    
    <!--license用于法律上的名称-->    
    <name>...</name>     
    <!--官方的license正文页面的URL-->    
    <url>....</url>
    <!--项目分发的主要方式:repo,可以从Maven库下载 manual, 用户必须手动下载和安装依赖-->    
    <distribution>repo</distribution>     
    <!--关于license的补充信息-->    
    <comments>....</comments>     
</license> 
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • organization:1.name 组织名 2.url 组织主页url
  • developers:项目开发人员列表(如下)
  • contributors:项目其他贡献者列表,同developers
<developers>  
    <!--某个开发者信息-->
    <developer>  
        <!--开发者的唯一标识符-->
        <id>....</id>  
        <!--开发者的全名-->
        <name>...</name>  
        <!--开发者的email-->
        <email>...</email>  
        <!--开发者的主页-->
        <url>...<url/>
        <!--开发者在项目中的角色-->
        <roles>  
            <role>Java Dev</role>  
            <role>Web UI</role>  
        </roles> 
        <!--开发者所属组织--> 
        <organization>sun</organization>  
        <!--开发者所属组织的URL-->
        <organizationUrl>...</organizationUrl>  
        <!--开发者属性,如即时消息如何处理等-->
        <properties>
            <!-- 和主标签中的properties一样,可以随意定义子标签 -->
        </properties> 
        <!--开发者所在时区, -11到12范围内的整数。--> 
        <timezone>-5</timezone>  
    </developer>  
</developers>  
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

6.环境设置

issueManagement

目的问题管理系统(Bugzilla, Jira, Scarab)的名称和URL

<issueManagement>
    <system>Bugzilla</system>
    <url>http://127.0.0.1/bugzilla/</url>
</issueManagement>

 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • system:系统类型
  • url:路径

ciManagement

项目的持续集成信息

  <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>
        <address>continuum@127.0.0.1</address>
        <configuration></configuration>
      </notifier>
    </notifiers>
  </ciManagement>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • system:持续集成系统的名字
  • url:持续集成系统的URL
  • notifiers:构建完成时,需要通知的开发者/用户的配置项。包括被通知者信息和通知条件(错误,失败,成功,警告) 
    • type:通知方式
    • sendOnError:错误时是否通知
    • sendOnFailure:失败时是否通知
    • sendOnSuccess:成功时是否通知
    • sendOnWarning:警告时是否通知
    • address:通知发送到的地址
    • configuration:扩展项

mailingLists

项目相关邮件列表信息

  <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
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • subscribe, unsubscribe: 订阅邮件(取消订阅)的地址或链接,如果是邮件地址,创建文档时,mailto: 链接会被自动创建
  • archive:浏览邮件信息的URL
  • post:接收邮件的地址

scm

允许你配置你的代码库,供Maven web站点和其它插件使用

  <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
  • 2
  • 3
  • 4
  • 5
  • 6
  • connection, developerConnection:这两个表示我们如何连接到maven的版本库。connection只提供读,developerConnection将提供写的请求 
    • 写法如:scm:[provider]:[provider_specific]
    • 如果连接到CVS仓库,可以配置如下:scm:cvs:pserver:127.0.0.1:/cvs/root:my-project
  • tag:项目标签,默认HEAD
  • url:共有仓库路径

prerequisites

项目构建的前提

<prerequisites>
    <maven>2.0.6</maven>
</prerequisites>
 
 
  • 1
  • 2
  • 3

repositories,pluginRepositories

依赖和扩展的远程仓库列表,同上篇文章,setting.xml配置中介绍的。

  <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
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • releases, snapshots:这是各种构件的策略,release或者snapshot。这两个集合,POM就可以根据独立仓库任意类型的依赖改变策略。如:一个人可能只激活下载snapshot用来开发。
  • enable:true或者false,决定仓库是否对于各自的类型激活(release 或者 snapshot)。
  • updatePolicy: 这个元素决定更新频率。maven将比较本地pom的时间戳(存储在仓库的maven数据文件中)和远程的. 有以下选择: always, daily (默认), interval:X (x是代表分钟的整型) , never.
  • checksumPolicy:当Maven向仓库部署文件的时候,它也部署了相应的校验和文件。可选的为:ignore,fail,warn,或者不正确的校验和。
  • layout:在上面描述仓库的时候,提到他们有统一的布局。Maven 2有它仓库默认布局。然而,Maven 1.x有不同布局。使用这个元素来表明它是default还是legacy。

distributionManagement

它管理的分布在整个构建过程生成的工件和支持文件

  <distributionManagement>
    ...
    <downloadUrl>http://mojo.codehaus.org/my-project</downloadUrl>
    <status>deployed</status>
  </distributionManagement>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • downloadUrl: 其他pom可以通过此url的仓库抓取组件
  • status:给出该构件在远程仓库的状态 
    • none: 默认
    • converted: 将被早期Maven 2 POM转换过来
    • partner: 这个项目会从合作者仓库同步过来
    • deployed: 从Maven 2或3实例部署
    • verified: 被核实时正确的和最终的

Repository

指定Maven pom从远程下载控件到当前项目的位置和方式,如果snapshotRepository没有被定义则使用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>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • id, name:仓库的唯一标识
  • uniqueVersion:true或false,指明控件部署的时候是否获取独立的版本号。
  • url:repository元素的核心。指定位置和部署协议发布控件到仓库。
  • layout:布局,default或legacy

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>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • id, name, url: 这些元素与distributionManagement repository中的相同

Relocation

重新部署-项目不是静态的,是活的。他们需要被搬到更合适的地方。如:当你的下个成功的开源项目移到Apache下,重命名为org.apache:my-project:1.0 对你项目更有好处。

  <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>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

profiles

profile可以让我们定义一系列的配置信息(插件等),然后指定其激活条件 
profile的相关配置可以参考上篇文章Maven实战(二)–setting.xml详解:

参考官方文档: http://maven.apache.org/pom.html


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值