如何使用父模块制作子模块的maven构建? [英] How to make maven build of child module with parent module?

查看:264
本文介绍了如何使用父模块制作子模块的maven构建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有多个模块,它们直接或传递地相互依赖。
当我编译«项目A»某些地方«项目D»自动生成。

I have multiple modules in my project and they are dependent on each other either directly or transitively. When I maven build «Project A» some where «Project D» gets build automatically.

Project A > Project B  > Project C > Project D

where > means Project B depends on Project A

«项目D»pom snipeet是:

«Project D» pom snipeet is:

<project xmlns="...">
    <modelVersion>4.0.0</modelVersion>  
    <groupId>com.myProduct</groupId>
    <artifactId>build-MyProjectD</artifactId>
    <name>MyProjectD</name>
    ........
</project>

构建«Project A»自动构建«Project B»,根据我的理解,实现这一目标某处 build-MyProjectD 应作为依赖项添加到其中一个项目中项目A>项目B>项目C 但我没有在这些项目的poms下找到任何字符串 build-MyProjectD 的引用。

As building «Project A» automatically build «Project B», as per my understanding to make this happen somewhere build-MyProjectD should be added as dependency in one of these projects Project A > Project B > Project C but I did not find any reference of string build-MyProjectD under poms of these projects.

在没有子项 artifactId 存在于上游项目的情况下,有什么其他方法可以构建子模块(在本例中为Project D)吗?

Any idea how is there any other way to make build of child module (in this case «Project D») without having child artifactId presence in upstream project?

推荐答案

您需要创建一个聚合器项目。有关聚合概念的更多信息,请参见链接。

You need to create an aggregator project. See the link for more information on the aggregation concept.

基本上,您创建一个包含多个模块的父项目。构建父级时,模块也会自动构建。

Basically, you create a parent project containing several "modules". When building the parent, the modules automatically gets built as well.

如果声明模块之间的依赖关系,Maven将以正确的顺序自动构建不同的模块,这样如果项目A依赖于项目B,项目B首先构建,然后项目A构建,以便其工件可用于构建第二个工件。

If you declare dependencies between the modules, Maven will automatically build the different modules in a correct order so that if «Project A» depends on «Project B», «Project B» is built first and then «Project A» is built so that its artifact is available for the building of the second artifact.

另请参阅 Maven常见问题解答中的这个问题

这篇关于如何使用父模块制作子模块的maven构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆