我是Maven的新手,我试图理解为什么我公司的模块被组织成'模块组',但每个子模块也明确声明它的父模块.我不太明白POM参考试图说明继承和聚合之间的区别.
例如,父模块:
<groupId>example.group</groupId>
<artifactId>util</artifactId>
<packaging>pom</packaging>
<name>Util Parent</name>
<modules>
<module>util_client</module>
<module>util_core</module>
<module>util_server</module>
</modules>
Run Code Online (Sandbox Code Playgroud)
其中一个孩子:
<parent>
<artifactId>util</artifactId>
<groupId>example.group</groupId>
<version>trunk-SNAPSHOT</version>
</parent>
<groupId>example.group.util</groupId>
<artifactId>util_core</artifactId>
<packaging>jar</packaging>
<name>Util Core</name>
Run Code Online (Sandbox Code Playgroud)
为什么要两种方式宣布?这是多余的吗?为了使事情更加混乱,一些util子模块依赖于彼此:
<groupId>example.group.util</groupId>
<artifactId>util_client</artifactId>
<packaging>jar</packaging>
<name>Util Client</name>
<dependencies>
<dependency>
<groupId>example.group.util</groupId>
<artifactId>util_core</artifactId>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
对不起,如果这是一个问题,但哇这令人困惑!谢谢你的帮助.
定义子模块时,可以从顶层一次构建和释放它们.
在第二个示例中使用继承时,可以使用一次定义的父POM中的定义(与要使用的软件版本一样)
在最后一个示例中,当一个模块需要来自另一个模块的资源时,您可以将其添加为依赖项,它将自动下载并将其包含在构建路径中.