- <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>
- <!-- The Basics -->
- <groupId>...</groupId>
- <artifactId>...</artifactId>
- <version>...</version>
- <packaging>...</packaging>
- <dependencies>...</dependencies>
- <parent>...</parent>
- <dependencyManagement>...</dependencyManagement>
- <modules>...</modules>
- <properties>...</properties>
- <!-- Build Settings -->
- <build>...</build>
- <reporting>...</reporting>
- <!-- More Project Information -->
- <name>...</name>
- <description>...</description>
- <url>...</url>
- <inceptionYear>...</inceptionYear>
- <licenses>...</licenses>
- <organization>...</organization>
- <developers>...</developers>
- <contributors>...</contributors>
- <!-- Environment Settings -->
- <issueManagement>...</issueManagement>
- <ciManagement>...</ciManagement>
- <mailingLists>...</mailingLists>
- <scm>...</scm>
- <prerequisites>...</prerequisites>
- <repositories>...</repositories>
- <pluginRepositories>...</pluginRepositories>
- <distributionManagement>...</distributionManagement>
- <profiles>...</profiles>
- </project>
<!-- The Basics -->
Maven坐标:
<groupId>,<artifactId>,<version>是必需字段。
打包方式<packaging>:
<packaging>:可选值有pom,jar,maven-plugin,ejb,war,ear,rar
依赖<dependencys>:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<type>jar</type>
<scope>test</scope>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
</exclusion>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<groupId>,<artifactId>,<version>:依赖项目的坐标。
<type>:依赖类型,默认类型是jar。
<scope>:范围可以使用5个值:
* compile,缺省值,适用于所有阶段,会随着项目一起发布。
* provided,类似compile,期望JDK、容器或使用者会提供这个依赖。如servlet.jar。
* runtime,只在运行时使用,如JDBC驱动,适用运行和测试阶段。
* test,只在测试时使用,用于编译和运行测试代码。不会随项目发布。
* system,类似provided,需要显式提供包含依赖的jar,Maven不会在Repository中查找。
<systemPath>:当且仅当<scope>值为system时可用,否则构建将失败。路径必须是绝对路径,因此建议使用属性指定特定于机器的路径,例如$ {java.home} / lib。
<optional>:表示此依赖项是否是必需的。默认值为false, 即子项目必须依赖。
<exclusion>:排除传递依赖项,可用通配符。
继承<parent>:
<parent>
<groupId>org.codehaus.mojo</groupId>
<artifactId>my-parent</artifactId>
<version>2.0</version>
<relativePath>../my-parent</relativePath>
</parent>
<groupId>,<artifactId>,<version>:父项目坐标。
<relativePath>:父项目的pom.xml文件的相对路径。默认值是../pom.xml。Maven首先在构建当前项目的地方寻找父项目的pom,其次在文件系统的这个位置(relativePath位置),然后在本地仓库,最后在远程仓库寻找父项目的pom。
依赖管理<dependencyManagement>:
<dependencyManagement>
<dependencies>
<dependency>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencyManagement>:用于帮助管理其所有子项目的依赖项信息。
import只在dependencyManagement元素下才有效果,作用是将目标POM中的dependencyManagement配置导入并合并到当前POM的dependencyManagement元素中。
聚合(多模块)<modules>:
<modules>
<module>my-project</module>
<module>another-project</module>
<module>third-project/pom-example.xml</module>
</modules>
聚合主要是为了方便快速构建项目,继承主要是为了消除重复配置。
聚合项目和父项目都是POM项目,同时,聚合模块与继承中的父模块除了POM外,都没有实际的内容。
它们不是同一个,不应该混淆。
属性<properties>:
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Maven属性是值占位符。通过使用符号$ {X},可以在POM内的任何位置访问它们的值,其中X是属性。有五种不同的风格:
- 内置属性:两个常用内置属性 ${basedir} 表示项目跟目录,即包含pom.xml文件的目录;${version} 表示项目版本。
- 环境变量属性:所有环境变量都可以使用以env.开头的Maven属性引用。例如${env.JAVA_HOME}指代了JAVA_HOME环境变量的值。也可以通过命令行mvn help:system查看所有环境变量。
注意:虽然环境变量本身在Windows上不区分大小写,但属性的查找区分大小写。换句话说,当Windows shell为%PATH%和%Path%返回相同的值时,Maven会区分$ {env.PATH}和$ {env.Path}。从Maven 2.1.0开始,为了可靠性,环境变量的名称被归一化为所有大写。
- POM属性: pom中对应元素的值。例如:<project> <version> 1.0 </ version> </project>可通过$ {project.version}访问。
- Settings属性:settings.xml里面包含相应的元素的值。例如:<settings> <offline> false </ offline> </ settings>可通过$ {settings.offline}访问。
- Java系统属性:所有Java系统属性都可以使用Maven属性引用,例如${user.home}指向了用户目录。可以通过命令行mvn help:system查看所有的Java系统属性}。
- 自定义属性:在POM中的<properties >元素内设置的值< properties > <someVar>值</ someVar> </ properties >可以被用作$ {someVar}。
注意: 部署服务器时,通过 -D 配置的属性也可以在maven中使用,如:
<rsa.path>classpath:${profile}config/RSA.properties</rsa. path>
Tomcat配置参数如下图:
<!-- Build Settings -->
构建<build>
<build> 有两种,一种<build>被称为Project Build,即是<project>的直接子元素。另一种<build>被称为Profile Build,即是<profile>的直接子元素。
<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
https://maven.apache.org/xsd/maven-4.0.0.xsd">
...
<!-- "Project Build" contains more elements than just the BaseBuild set -->
<build>...</build>
<!-- "Profile Build" contains a subset of "Project Build"s elements -->
<profiles>
<profile>
<build>
<defaultGoal>install</defaultGoal>
<directory>${basedir}/target</directory>
<finalName>${artifactId}-${version}</finalName>
<filters>
<filter>filters/filter1.properties</filter>
</filters>
</build>
</profile>
</profiles>
</project>
<defaultGoal>:执行build任务时,如果没有指定目标,将使用的默认值,如:在命令行中执行mvn,则相当于执行mvn install。
<directory>:构建将转储其文件的目录,或者在Maven的说法中,构建的目标。默认在${basedir}/target目录。
<finalName>:build目标文件的文件名,默认情况下为${artifactId}-${version}
<filter>:定义*.properties文件,包含一个properties列表,当<resources>中<filtering>值为true时,定义在filter的文件中的"name=value"值对会在build时代替${name}值应用到<resources>中。Maven的默认filter文件夹是${basedir}/src/main/filters/。
资源<resources>:
build的另一个特征是指定你的项目中resources的位置。
<build>
...
<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>
</resources>
<testResources>
...
</testResources>
...
</build>
<resource>:描述与项目关联的文件是什么和在哪里。
<targetPath>:指定build后的resource存放的文件夹。该路径默认是basedir。通常被打包在JAR中的resources的目标路径为META-INF;
<filtering>:表示为这个resource是否激活filter。
<directory>:定义resource所在的文件夹,默认为${basedir}/src/main/resources。(和build的区别。)
<includes>:指定作为resource的文件的匹配模式,用*作为通配符。
<excludes>:指定哪些文件被忽略,如果一个文件同时符合includes和excludes,则excludes生效。
<testResources>:定义和resource类似,但只在test时使用,默认的test resource文件夹路径是${basedir}/src/test/resources,test resource不被部署。
插件<plu gins>
<build>
...
<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>
</plugins>
</build>
<groupId>,<artifactId>,<version>:标准坐标。
<extensions>:是否加载此插件的扩展(extensions),默认为false 。
<inherited>:,此插件配置是否应该应用于从此继承的POM,默认true。
<configuration>:配置该插件期望得到的属性,如上面的例子,我们为maven-jar-plugin的Mojo设置了classifier属性。(例子)
<dependencies>:同base build中的dependencies有同样的结构和功能,但这里是作为plugin的依赖,而不是项目的依赖。
<executions>:插件可以有多个目标,每个目标可以具有单独的配置,甚至可能将插件的目标完全绑定到不同的阶段。executions配置一个plugin的目标的execution。例如要将antrun:run目标绑定到验证阶段。我们希望该任务回显构建目录,并通过将inherited设置为false来避免将此配置传递给其子项(假设它是父项),配置如下:
<executions>
<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>
</executions>
<id>:标识,用于和其他execution区分。当这个阶段执行时,它将以这个形式展示:[plugin:goal execution: id]。在这里为: [antrun:run execution: echodir]。
<goals>:一个plugin的execution的目标列表。
<phase>:目标执行的阶段,具体值看Maven的生命周期列表。
<inherited>:是否继承。设置这个false会让Maven无法将这个执行传递给它的子元素。此元素仅对父POM有意义。
<configuration>:在指定的目标下的配置。
示例:<configuration> 合并
父POM:
<plugin>
<groupId>my.group</groupId>
<artifactId>my-plugin</artifactId>
<configuration>
<items>
<item>parent-1</item>
<item>parent-2</item>
</items>
<properties>
<parentKey>parent</parentKey>
</properties>
</configuration>
</plugin>
子POM:
<plugin>
<groupId>my.group</groupId>
<artifactId>my-plugin</artifactId>
<configuration>
<items>
<item>child-1</item>
</items>
<properties>
<childKey>child</childKey>
</properties>
</configuration>
</plugin>
这样子POM和父POM中都存在groupId为my.group的plugin,Maven默认的行为将是根据属性名称将两个plugin的configuration的内容进行合并。如果子POM中有一个属性,则该属性是有效的,如果子POM中没有一个属性,但父POM中存在,则父POM中的属性是有效的。根据这些规则,上面的例子在Maven中将得到:
<plugin>
<groupId>my.group</groupId>
<artifactId>my-plugin</artifactId>
<configuration>
<items>
<item>child-1</item>
</items>
<properties>
<childKey>child</childKey>
<parentKey>parent</parentKey>
</properties>
</configuration>
</plugin>
通过在configuration元素中增加combine.children和combine.self属性,孩子POM可以控制Maven怎么合并plugin的configuration。
假定这儿是孩子POM的configuration:
<plugin>
<groupId>my.group</groupId>
<artifactId>my-plugin</artifactId>
<configuration>
<items combine.children="append">
<!-- combine.children="merge" is the default -->
<item>child-1</item>
</items>
<properties combine.self="override">
<!-- combine.self="merge" is the default -->
<childKey>child</childKey>
</properties>
</configuration>
</plugin>
现在合并后的效果如下:
<plugin>
<configuration>
<items combine.children="append">
<item>parent-1</item>
<item>parent-2</item>
<item>child-1</item>
</items>
<properties combine.self="override">
<childKey>child</childKey>
</properties>
</configuration>
</plugin>
combine.children="append"表示父POM和子POM的属性合并起来。
combine.self="override"表示子POM的属性完全覆盖父POM的。
不能同时在一个元素上同时使用combine.self =“override”和combine.children =“append” , 如果你尝试,覆盖将占上风。
插件管理<pluginManagement>:
pluginManagement的元素的配置和plugins的配置是一样的,只是这里的配置只是用于集成,在子POM中指定使用。子POM有权重写pluginManagement定义。父POM中做如下配置:
<build>
...
<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>
...
</build>
则在孩子POM中,我们只需要配置:
<build>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
</plugins>
...
</build>
Project Build特有元素
<build>
<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>
...
</build>
目录可以使用绝对路径,如示例所示。如果使用相对路径,则所有的相对路径都是在${basedir}目录下。
<sourceDirectory>设置了项目源码目录,当构建项目的时候,构建系统会编译目录里的源码。该路径是相对于pom.xml的相对路径。
<scriptSourceDirectory>在Maven中没有使用,已经过时了。
<testSourceDirectory>设置了项目单元测试使用的源码目录,当测试项目的时候,构建系统会编译目录里的源码。
<outputDirectory>被编译过的应用程序class文件存放的目录。
<testOutputDirectory>被编译过的测试class文件存放的目录
<build>
...
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ftp</artifactId>
<version>1.0-alpha-3</version>
</extension>
</extensions>
...
</build>
扩展是要在此构建中使用的工件列表。它们将包含在正在运行的构建的类路径中。他们可以启用构建过程的扩展(例如为Wagon传输机制添加ftp提供程序),以及使插件处于活动状态,从而对构建生命周期进行更改。简而言之,扩展是在构建期间激活的工件。扩展不必实际执行任何操作,也不必包含Mojo。出于这个原因,扩展非常适合指定常见插件接口的多个实现中的一个。
报告<reporting>
作用于Maven的site阶段,用于生成报表。<reporting>中也可以配置插件<plugins>,并通过一个<plugin>的<reportSet>为该插件配置参数。报告<reporting>元素下的插件配置可用作构建<build>插件配置,但相反的情况则不然(构建插件)配置不会影响报告插件)。
<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
https://maven.apache.org/xsd/maven-4.0.0.xsd">
...
<reporting>
<outputDirectory>${basedir}/target/site</outputDirectory>
<plugins>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.0.1</version>
<reportSets>
<reportSet></reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
...
</project>
<outputDirectory>所有产生的报表存放到哪里。默认值是${project.build.directory}/site。
<!-- More Project Information -->
其他项目信息
<name>:项目的名称, Maven产生的文档用
<description>:项目描述虽然这不应取代正式文档,但对POM的任何读者的快速评论总是有帮助的。
<url>:项目主页的URL, Maven产生的文档用,URL不是必需的。
<inceptionYear>:项目创建年份,4位数字。当产生版权信息时需要使用这个值。
许可证<license>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
<comments>A business-friendly OSS license</comments>
</license>
</licenses>
<name>:用于法律上的名称。
<url>:官方的license正文页面的URL。
<distribution>:项目分发的方式:repo:可以从Maven库下载; manual:用户必须手动下载和安装依赖.
<comments>:关于license的补充信息。
<!-- Environment Settings -->
问题管理系统< issueManagement >
这定义了使用的问题管理系统(Bugzilla,TestTrack,ClearQuest等)。虽然没有什么能阻止插件使用这些信息,但它主要用于生成项目文档。
<issueManagement>
<system>Bugzilla</system>
<url>http://127.0.0.1/bugzilla/</url>
</issueManagement>
<system>:问题管理系统(例如bugzilla)的名字。
<url>:该项目使用的问题管理系统的URL。
持续集成管理< ciManagement >
于触发器或计时(例如,每小时或每天)的持续集成构建系统在过去几年中已经越来越有利于手动构建。随着构建系统变得更加标准化,运行触发器的系统也会变得更加标准化。尽管大多数配置取决于所使用的特定程序(Continuum,Cruise Control等),但在POM中可能会发生一些配置。Maven已经捕获了一组通知元素中的一些重复设置。通知程序是指人们收到某些构建状态的通知方式。
<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>
<system>:持续集成系统的名字,例如continuum
<url>:该项目使用的持续集成系统的URL(如果持续集成系统有web接口的话)
<notifier>:构建完成时,需要通知的开发者/用户的配置项。
<type>:传送通知的类型。
<sendOnError>:发生错误时是否通知。
<sendOnFailure>:构建失败时是否通知。
<sendOnSuccess>:构建成功时是否通知。
<sendOnWarning>:发生警告时是否通知。
<configuration>:扩展配置项。
邮件列表<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>
<name>:邮件的名称。
<subscribe>:订阅邮件的地址或链接
<unsubscribe>:取消订阅邮件的地址或链接
<post>:发送邮件的地址或链接
<archive>:可以浏览邮件信息的URL
<otherArchives>:
SCM
SCM(软件配置管理,也称为源代码/控制管理,版本控制)是任何健康项目的组成部分。如果您的Maven项目使用SCM系统,那么您可以在此处将该信息放入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>
<connection>:SCM的URL,该URL描述了版本库和如何连接到版本库,该连接只读。
<developerConnection>:给开发者使用的,类似connection元素。即该连接不仅仅只读。
<tag>:指定此项目所在的标记。HEAD(意思是SCM根目录)应该是默认值。
<url>:指向项目的可浏览SCM库(例如ViewVC或者Fisheye)的URL。
先决条件<Prerequisites>
POM可能具有某些先决条件以便正确执行。下例表示构建该项目或使用该插件所需要的Maven的最低版本为2.0.6 。
<prerequisites>
<maven>2.0.6</maven>
</prerequisites>
库<Repositories>
Maven中的库(repository)是构件(artifact)的集合。构件以一定的布局存储在库中。
<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>
<releases>,<snapshots>:Release则代表稳定的版本,Snapshot代表不稳定、尚处于开发中的版本。
<enabled>:true或者false表示该仓库是否为下载某种类型构件(发布版,快照版)开启。
<updatePolicy>:该元素指定更新发生的频率。Maven会比较本地POM和远程POM的时间戳。这里的选项是:always(一直),daily(默认,每日),interval:X(这里X是以分钟为单位的时间间隔),或者never(从不)。
<checksumPolicy>:当Maven验证构件校验文件失败时该怎么做:ignore(忽略),fail(失败),或者warn(警告)。
<id>:远程仓库唯一标识符。可以用来匹配在settings.xml文件里配置的远程仓库。
<name>:远程仓库名称。
<url>:远程仓库URL,按protocol://hostname/path形式。
<layout>:用于定位和排序构件的仓库布局类型-可以是default(默认)或者legacy(遗留)。Maven 2为其仓库提供了一个默认的布局;然而,Maven 1.x有一种不同的布局。我们可以使用该元素指定布局是default(默认)还是legacy(遗留)。
插件存储库<pluginRepositories>
pluginRepositories元素块的结构类似于repositories元素。该pluginRepository每个元素指定的地方Maven可以找到新的插件远程位置。
分布管理<Distribution Management>
分发管理就像听起来一样:它管理工件的分发和在整个构建过程中生成的支持文件。在执行mvn deploy后表示要发布的位置。有了这些信息就可以把网站部署到远程服务器或者把构件部署到远程仓库。
<distributionManagement>
<repository>
<uniqueVersion>false</uniqueVersion>
<id>corp1</id>
<name>Corporate Repository</name>
<url>scp://repo/maven2</url>
<layout>default</layout>
</repository>
<uniqueVersion>true</uniqueVersion>
<id>propSnap</id>
<name>Propellors Snapshots</name>
<url>sftp://propellers.net/maven</url>
<layout>legacy</layout>
</snapshotRepository>
<site>
<id>mojo.website</id>
<name>Mojo Website</name>
<url>scp://beaver.codehaus.org/home/projects/mojo/public_html/</url>
</site>
<relocation>
<groupId>org.apache</groupId>
<artifactId>my-project</artifactId>
<version>1.0</version>
<message>We have moved the Project under Apache</message>
</relocation>
<downloadUrl>http://mojo.codehaus.org/my-project</downloadUrl>
<status>deployed</status>
</distributionManagement>
<repository>:项目产生的构件部署到远程仓库需要的信息。
<uniqueVersion>:是分配一个唯一的版本号(由时间戳和构建流水号)?还是每次都使用相同的版本号?
<id>,<name>:id用于在许多中唯一标识此存储库,name是可读的形式。
<url>:指定用于将构建的工件(以及POM文件和校验和数据)传输到存储库的位置和传输协议。(核心)
<layout>:这些类型和用途与repository元素中定义的layout元素相同。
<snapshotRepository>:构件的快照部署位置,如果没有配置,默认部署到repository元素配置的仓库。
<site>:部署项目的网站需要的信息。
<id>:部署位置的唯一标识符,用来匹配站点和settings.xml文件里的配置。
<name>,<url>:与上面的类似。
<relocation>:如果构件有了新的group ID和artifact ID(构件移到新位置),这里列出构件重定位信息。
<message>:显示给用户的,关于移动的额外信息,例如原因。
<downloadUrl>:项目下载页面的URL。
<status>:给出该构件在远程仓库的状态。不得在本地项目中设置该元素,因为这是工具自动更新的,Maven在将项目传输到存储库时会设置项目的状态。有效的值有:
none:默认值。
converted:存储库的管理员将此POM从早期版本转换为Maven 2。
partner:此工件已与合作伙伴存储库同步。
deployed:迄今为止最常见的状态,意味着此工件是从Maven 2或3实例部署的。这是使用命令行部署阶段手动部署时获得的结果.。
verified:此项目已经过验证,应该考虑最终确定。
配置文件<profiles>
POM 4.0的一个新功能是项目根据构建环境更改设置的能力。
<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>
<build>...</build>
<modules>...</modules>
<repositories>...</repositories>
<pluginRepositories>...</pluginRepositories>
<dependencies>...</dependencies>
<reporting>...</reporting>
<dependencyManagement>...</dependencyManagement>
<distributionManagement>...</distributionManagement>
</profile>
</profiles>
<profile>:根据环境参数或命令行参数激活某个构建处理。
<id>:构建配置的唯一标识符。即用于命令行激活,也用于在继承时合并具有相同标识符的profile。
<activation>:触发profile的条件逻辑。Activation是profile的开启钥匙。profile的力量来自于它能够在某些特定的环境中自动使用某些特定的值;这些环境通过activation元素指定。
<activeByDefault>:默认是否激活的标志。
<jdk>:测试是在与给定前缀匹配的jdk版本号下运行,则会激活此选项。在上面的例子中,1.5.0_06将匹配。从Maven 2.1开始也支持范围。
<os>:可以定义上面显示的一些特定于操作系统的属性。
<property>:如果Maven检测到某一个属性(其值可以在POM中通过${名称}引用),其拥有对应的名称和值,Profile就会被激活。如果值字段是空的,那么存在属性名称字段就会激活profile,否则按区分大小写方式匹配属性值字段。
<file>:提供一个文件名,通过检测该文件的存在或不存在来激活profile。missing检查文件是否存在,如果不存在则激活profile。另一方面,exists则会检查文件是否存在,如果存在则激活profile。注意:此元素的插值仅限于$ {basedir},系统属性(System properties)和请求属性(request properties)。
注意:<activation>元素不是激活<profile>的唯一方式。通过settings.xml的文件的activeProfile元素可以包含配置文件的<id>。也可以通过命令行在-P标志之后通过逗号分隔列表显式激活(例如-P codecoverage)
lifecycle与phase与goal与mojo的概念(待完善)
maven对构建(build)的过程进行了抽象和定义,这个过程被称为构建的生命周期(lifecycle)。生命周期(lifecycle)由多个阶段(phase)组成,每个阶段(phase)会挂接一到多个goal。goal是maven里定义任务的最小单元。
使用install在本地仓库添加依赖。例:
mvn install:install-file -Dfile=jar包的位置(如D:\mvn\spring-context-support-3.1.0.RELEASE.jar) -DgroupId=groupId -DartifactId=artifactId -Dversion= version
-Dpackaging=jar