为什么有时依赖项不包含 pom.xml 中的版本 属性?
Why sometimes dependency not contain version property in pom.xml?
我是Maven的新手,目前正在阅读Hadoop源代码,在一些pom.xml
个文件中发现了一些有趣的东西:
一些依赖节点根本不包含版本节点。
问题:为什么会这样?
例如,this pom.xml
。
在 Maven 中,您可以继承父文件夹以合并或继承某些属性。这可以是模块的版本。通常你在项目的根文件夹中有一个 "super" POM,你把所有的公共依赖项放在那里,以便以更简单的方式控制它们。 IE。如果你必须改变一个模块版本,你只需要在 "super" POM 中改变,而不是在每个需要它的子文件夹中的每个 POM 中。如果您需要有关 POM 继承的更多信息,文档中有几个有用的示例。
https://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Project_Inheritance
因为 parent pom.xml
文件
中依赖的特定版本
https://github.com/apache/hadoop/blob/trunk/pom.xml
参考:https://maven.apache.org/guides/introduction/introduction-to-the-pom.html
正如我最初评论的那样,一个 pom 文件可以有一个父文件(通过 inheritance) and such a parent may provide some governance and harmonization across all of its children. A classic case is to provide versioning for certain dependencies via a dependencyManagement
部分。
is used by POMs to help manage dependency information across all of its children. If the my-parent
project uses dependencyManagement
to define a dependency on junit:junit:4.0
, then POMs inheriting from this one can set their dependency giving the groupId=junit and artifactId=junit only, then Maven will fill in the version set by the parent. The benefits of this method are obvious. Dependency details can be set in one central location, which will propagate to all inheriting POMs.
提到的pom确实有父pom:
<parent>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-project-dist</artifactId>
<version>3.0.0-SNAPSHOT</version>
<relativePath>../../hadoop-project-dist</relativePath>
</parent>
链中有 another parent pom 文件,该文件定义了几个依赖项作为其依赖项管理部分的一部分。
如果你真的想检查你的构建正在使用的有效(合并)pom,你可以 运行:
mvn help:effective-pom -Doutput=effective-pom.xml
并且 maven-help-plugin
将按照上面的命令生成一个额外的 pom,合并当前的 pom 文件及其所有锚点。
我是Maven的新手,目前正在阅读Hadoop源代码,在一些pom.xml
个文件中发现了一些有趣的东西:
一些依赖节点根本不包含版本节点。
问题:为什么会这样?
例如,this pom.xml
。
在 Maven 中,您可以继承父文件夹以合并或继承某些属性。这可以是模块的版本。通常你在项目的根文件夹中有一个 "super" POM,你把所有的公共依赖项放在那里,以便以更简单的方式控制它们。 IE。如果你必须改变一个模块版本,你只需要在 "super" POM 中改变,而不是在每个需要它的子文件夹中的每个 POM 中。如果您需要有关 POM 继承的更多信息,文档中有几个有用的示例。
https://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Project_Inheritance
因为 parent pom.xml
文件
https://github.com/apache/hadoop/blob/trunk/pom.xml
参考:https://maven.apache.org/guides/introduction/introduction-to-the-pom.html
正如我最初评论的那样,一个 pom 文件可以有一个父文件(通过 inheritance) and such a parent may provide some governance and harmonization across all of its children. A classic case is to provide versioning for certain dependencies via a dependencyManagement
部分。
is used by POMs to help manage dependency information across all of its children. If the
my-parent
project usesdependencyManagement
to define a dependency onjunit:junit:4.0
, then POMs inheriting from this one can set their dependency giving the groupId=junit and artifactId=junit only, then Maven will fill in the version set by the parent. The benefits of this method are obvious. Dependency details can be set in one central location, which will propagate to all inheriting POMs.
提到的pom确实有父pom:
<parent>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-project-dist</artifactId>
<version>3.0.0-SNAPSHOT</version>
<relativePath>../../hadoop-project-dist</relativePath>
</parent>
链中有 another parent pom 文件,该文件定义了几个依赖项作为其依赖项管理部分的一部分。
如果你真的想检查你的构建正在使用的有效(合并)pom,你可以 运行:
mvn help:effective-pom -Doutput=effective-pom.xml
并且 maven-help-plugin
将按照上面的命令生成一个额外的 pom,合并当前的 pom 文件及其所有锚点。