Java Maven 构建顺序(多个模块)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18629897/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 09:40:03  来源:igfitidea点击:

Maven build order (Multiple modules)

javamavenbuild

提问by testndtv

I have a Maven parent project which has multiple child/modules...I have the following pom.xml for the main/parent;

我有一个 Maven 父项目,它有多个子/模块......我有以下主要/父级的 pom.xml;

<modules>
        <module>Main-Ear</module>
        <module>Sub-Web</module>
        <module>Sub-Ui</module>
        <module>Sub-Services</module>
        <module>Sub-SSO-Login</module>
  </modules>

However, I find the actual build order to be different... After build, the actual order looks like;

但是,我发现实际的构建顺序不同......构建后,实际顺序看起来像;

Main
Sub-Services
Sub-SSO-Login
Sub-UI
Sub-Web
Main-Ear

Where exactly does Maven take the build order from in this case?

在这种情况下,Maven 究竟从哪里获取构建顺序?

回答by Ruchira Gayan Ranaweera

Mavennot taken the module building order from what we define in the main pom.xml. Mavendecide the order by considering module dependencies with each other modules.

Maven没有从我们在 main 中定义的模块构建顺序中获取pom.xmlMaven通过考虑模块与其他模块的依赖关系来决定顺序。

In your case definitely Main-Earshould build last.

在你的情况下绝对Main-Ear应该建立最后。

Let's consider following example.

让我们考虑以下示例。

I have module A, Band C. Module Ahas dependency from module Cand Bwhile module Chas dependency from module B. Then mavenbuilding order will be

我有模块A,BC. ModuleA依赖于 module CB而 moduleC依赖于 module B。然后maven建筑订单将是

B
C
A  

回答by Sambuca

You can't manually control the build order:

您无法手动控制构建顺序:

From Maven project documentation (Guide to Working with Multiple Modules):

来自 Maven 项目文档(使用多个模块的指南):

Reactor Sorting

Because modules within a multi-module build can depend on each other, it is important that The reactor sorts all the projects in a way that guarantees any project is built before it is required.

The following relationships are honoured when sorting projects:

  • a project dependency on another module in the build
  • a plugin declaration where the plugin is another modules in the build
  • a plugin dependency on another module in the build
  • a build extension declaration on another module in the build the order declared in the element (if no other rule applies)

Note that only "instantiated" references are used - dependencyManagement and pluginManagement elements will not cause a change to the reactor sort order

反应堆分类

由于多模块构建中的模块可以相互依赖,因此反应器以确保任何项目在需要之前构建的方式对所有项目进行排序非常重要。

排序项目时遵循以下关系:

  • 项目依赖于构建中的另一个模块
  • 插件声明,其中插件是构建中的另一个模块
  • 插件依赖于构建中的另一个模块
  • 构建中另一个模块上的构建扩展声明 元素中声明的顺序(如果没有其他规则适用)

请注意,仅使用“实例化”引用——dependencyManagement 和 pluginManagement 元素不会导致反应器排序顺序发生变化