【问题标题】:How does Maven order modules in the reactorMaven如何在reactor中排序模块
【发布时间】:2017-02-16 02:48:02
【问题描述】:

这样的问题已经被问了一遍又一遍,但不知何故,他们只关注依赖关系。所以根据mavendocumentation的构建顺序确定如下。

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

第一条规则很明确,例如如果模块 A 依赖于模块 B,则后者首先构建。

第五条规则(最后一条)也很清楚。如果前三个规则不适用,我们查看模块部分中的顺序。

其他两条规则对我来说不是很清楚。英语不是我的母语,但我想知道规则二是否包含某种错字。

我正在寻找一个简单的例子来详细解释这两个规则。

【问题讨论】:

  • 最好将项目显示为示例(可能在 github 上),以便更容易查看...
  • 你不能通过声明从 A 到 C 的依赖来“解决”你的问题吗?
  • 实际上,我对那个特定问题的解决方案不感兴趣。所以我编辑了这个问题以删除它。我真的很想知道这些排序规则是如何工作的。

标签: maven maven-module maven-reactor


【解决方案1】:

Let's go through them一一。

  • 项目依赖于构建中的另一个模块

这意味着如果模块 A 依赖于模块 B,则 B 必须在 A 之前构建。这处理了在 A 的 POM 中,您将拥有:

<dependencies>
  <dependency>
    <groupId>${project.groupId}</groupId>
    <artifactId>B</artifactId>
    <version>${project.version}</version>
  </dependency>
</dependencies>
  • 插件声明,其中插件是构建中的另一个模块

这意味着如果模块 A 使用模块 B 的 a Maven plugin,则 B 必须在 A 之前构建。这处理了在 A 的 POM 中,您将拥有:

<build>
  <plugins>
    <plugin>
      <groupId>${project.groupId}</groupId>
      <artifactId>B</artifactId>
      <version>${project.version}</version>
    </plugin>
  </plugins>
</build>
  • 插件依赖于构建中的另一个模块

这意味着如果模块 A 在模块 B 上使用 Maven 插件 that has a dependency,则 B 必须在 A 之前构建。这处理了在 A 的 POM 中,您将拥有:

<build>
  <plugins>
    <plugin>
      <groupId>some.plugin.groupId</groupId>
      <artifactId>some.plugin.artifactId</artifactId>
      <version>some.version</version>
      <dependencies>
        <dependency>
          <groupId>${project.groupId}</groupId>
          <artifactId>B</artifactId>
          <version>${project.version}</version>
        </dependency>
      </dependencies>
    </plugin>
  </plugins>
</build>

注意这条规则是在最后一条之后应用的,所以即使插件本身也是构建的一个模块,也会在之前构建,确保解析依赖是安全的。

  • 构建中另一个模块的构建扩展声明

这意味着如果一个模块 A 声明使用 as extention 一个模块 B,那么 B 必须在 A 之前构建。这处理了在 A 的 POM 中,你会有:

<build>
  <extensions>
    <extension>
      <groupId>${project.groupId}</groupId>
      <artifactId>B</artifactId>
      <version>${project.version}</version>
    </extension>
  </extensions>
</build>
  • &lt;modules&gt; 元素中声明的顺序(如果没有其他规则适用)

当没有应用前面的规则时,顺序是&lt;modules&gt; 的顺序,看起来像聚合器项目的POM:

<modules>
  <module>A</module>
  <module>B</module>
</modules>

如果前面的规则都不适用,A 将在 B 之前构建。

【讨论】:

  • 非常感谢您的明确回答。您应该考虑将这些作为新文档的示例...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-07-27
  • 1970-01-01
  • 2012-09-13
  • 2016-01-09
  • 2016-01-02
  • 1970-01-01
  • 2017-05-22
相关资源
最近更新 更多