模板
<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.0http://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>
基本配置
| modelVersion | Maven模块版本,目前我们一般都取值4.0.0 |
|---|---|
| groupId | 分组名称,一般域名倒叙。 |
| artifactId | 项目名称或子模块名称。 |
| version | 版本号 - *-SNAPSHOT 不稳定版本 |
- 存放在快照仓库,构建时远程抓取
- *-RELEASE 稳定版本
- 存放在正式仓库,构建的时会先在本次仓库中查找是否已经有了这个依赖库,如果没有的话才会去远程仓库中去拉取
|
| name | 项目名称 |
| description | 项目描述 |
| packaging | 打包类型,可取值:jar,war,maven-plugin等等,这个配置用于package的phase,具体可以参见package运行的时候启动的plugin, |
parent
继承父类
<parent><groupId>com.yuyu</groupId><artifactId>yuyu-nexus-parent-pom</artifactId><version>0.0.2.RELEASE</version>
modules
声明子模块
<modules><module>sales-mall</module><module>sales-middle</module></modules>
Dependencies
项目所需要的依赖包
| groupId | 依赖项的groupId |
|---|---|
| artifactId | 依赖项的artifactId |
| version | 依赖项的版本 |
| scope | 依赖项的适用范围: - compile,缺省值,适用于所有阶段,会随着项目一起发布。 |
- provided,类似compile,期望JDK、容器或使用者会提供这个依赖。如servlet.jar。
- runtime,只在运行时使用,如JDBC驱动,适用运行和测试阶段。
- test,只在测试时使用,用于编译和运行测试代码。不会随项目发布。
- system,类似provided,需要显式提供包含依赖的jar,Maven不会在Repository中查找它。之前例子里的junit就只用在了test中。
|
| exclusions | 排除项目中的依赖冲突时使用。 |
exclusions
- 排除告诉Maven不要包括指定的项目依赖的这种依赖性(换句话说,它的传递依赖)。例如,maven-embedder需要maven-core,我们不希望使用它或其依赖项,然后我们将它排除。
<dependencies><dependency><groupId>org.apache.maven</groupId><artifactId>maven-embedder</artifactId><version>2.0</version><exclusions><exclusion><groupId>org.apache.maven</groupId><artifactId>maven-core</artifactId></exclusion></exclusions></dependency>...</dependencies>
- 它有时也有用片段依赖的传递依赖关系。依赖可能错误地指定的范围,与其他依赖或依赖项冲突在您的项目。使用通配符不便于排除所有依赖的传递依赖项。在下面的情况下你可能会使用maven-embedder和你想管理依赖你自己使用,所以你剪辑传递依赖关系:
<dependency><groupId>org.apache.maven</groupId><artifactId>maven-embedder</artifactId><version>3.1.0</version><exclusions><exclusion><groupId>*</groupId><artifactId>*</artifactId></exclusion></exclusions></dependency>
build
构建
<build><finalName>sales-middle-service</finalName><resources><resource><directory>${project.basedir}/src/main/resources</directory><includes><include>**/*.properties</include><include>**/*.xml</include></includes><filtering>false</filtering></resource><resource><directory>${project.basedir}/src/main/java</directory><includes><include>**/*.properties</include><include>**/*.xml</include></includes><filtering>false</filtering></resource></resources></build>
| finalName | 项目打包后的名字 |
|---|---|
| resources | 配置文件 |
| filter | 可以把属性写到文件里,用属性文件里定义的属性做替换 |
