0%

pom 关系

POM 关系

Maven 一个很强的地方是它的对于项目关系的处理,包含了依赖(transitive dependencies,在这里可能应该理解为传递依赖),继承,和聚合(多模块项目)。

Dependencies 依赖

1
2
3
4
5
6
7
8
9
10
11
12
13
...
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<type>jar</type>
<scope>test</scope>
<optional>true</optional>
</dependency>
...
</dependencies>
...

groupId、artifactId、version:
这里的 version 还可以用一种专门的语法来约束,不需要指定固定的某一个版本,这个知识点在别的笔记里面记录过,这个知识点 JS、Python 也都是使用。

classifier:

The classifier distinguishes artifacts that were built from the same POM but differ in content. It is some optional and arbitrary string that - if present - is appended to the artifact name just after the version number.
As a motivation for this element, consider for example a project that offers an artifact targeting Java 11 but at the same time also an artifact that still supports Java 1.8. The first artifact could be equipped with the classifier jdk11 and the second one with jdk8 such that clients can choose which one to use.
Another common use case for classifiers is to attach secondary artifacts to the project’s main artifact. If you browse the Maven central repository, you will notice that the classifiers sources and javadoc are used to deploy the project source code and API docs along with the packaged class files.

这个好像是说制品根据这个属性可以有不同的分类,例如可以生成支持 Java 11 的或者生成 Java 1.8 的,或者还可以生成附属的制品,例如 sources 和 javadoc。
其实总体来说,还是有些不明白。

type:
依赖的类型,默认是 jar。

scope:
范围,这个元素指的是手头任务的 classpath,以及如何限制依赖的传递性。
这个在 gradle 里面有对应的动词,可以对应总结一下。
在这里插入图片描述
in hand vs at hand vs on hand 的区别:
在这里插入图片描述

systemPath:

optional:

参考

https://maven.apache.org/pom.html#pom-relationships