groupId 此元素指示创建项目的组织或组的唯一标识符。 groupId是项目的关键标识符之一,通常基于组织的完全限定域名。 例如,org.apache.maven.plugins 是所有Maven插件的指定groupId。

${basedir} represents the directory containing pom.xml

http://repo.maven.apache.org/maven2

Note that you can use the element to gain more control over the order of particular goals.

Project Inheritance - 项目继承

Introduce your own parent POMs by specifying the parent element in the POM

子模块会继承父项目的配置项

1
2
3
4
5
6
7
8
9
10
<project>
<parent>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>my-module</artifactId>
</project>

备注:

  • 子模块未指定 groupIdvsersion, 将会从父 POM 中继承

  • 如果父项目没有安装在 repository 中或者父项目与子模块的目录层级不是下面这种:

1
2
3
4
.
|-- my-module
| `-- pom.xml # 子模块的POM
`-- pom.xml # 父POM

那么就需要通过 relativePath 标签指定父 POM 的路径,相对路径,相对于子模块的 POM 的路径

Project Aggregation - 项目聚合(集成)

Instead of specifying the parent POM from the module, it specifies the modules from the parent POM

父项目中知道自己有哪些子模块,在父项目中调用了 Maven 命令, 这些 Maven 命令也会在子模块中执行。

  • 在父 POM 中指定 packaging 的值为 “pom”
1
<packaging>pom</packaging>
  • 在父 POM 中指定子模块(子PMO)的目录 -相对路径,相对于父 POM 的路径
1
2
3
4
<modules>
<module>my-module</module>
<module>../my-module</module>
</modules>

Dependency mediation

这将确定在遇到多个版本作为依赖项时将选择哪个版本的工件。 Maven选择“最接近的定义”。 也就是说,它在依赖树中使用与项目最接近的依赖项版本。 您可以通过在项目的POM中明确声明它来保证版本。 请注意,如果两个依赖项版本在依赖关系树中处于相同深度,则第一个声明将获胜。

1
2
3
4
5
6
mvn archetype:generate \
-DgroupId=com.mycompany.app \
-DartifactId=my-app \
-DarchetypeArtifactId=maven-archetype-quickstart \
-DarchetypeVersion=1.4 \
-DinteractiveMode=false

URI is not registered (Settings | Languages & Frameworks | Schemas and DTDs)

assembly 3.1 和 2.5 的版本竟然会之执行不一样,

1
2
3
<scope>provided</scope>
<!--禁止传递依赖-->
<useTransitiveDependencies>true</useTransitiveDependencies>

3.1 版本, useTransitiveDependencies 设置为 true, scope 为 provided 的依赖不会拉进来?