Maven如何在反应堆中订购模块

pja*_*sen 6 maven maven-reactor maven-module

像这样的问题一直被问到,但不知怎的,他们只关注依赖性.因此,根据maven 文档,构建顺序确定如下.

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

第一条规则是退出清除,例如,如果模块A依赖于模块B,则后者首先构建.

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

另外两条规则对我来说并不清楚.英语不是我的母语,但我想知道规则二是否包含某种拼写错误.

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

Tun*_*aki 7

让我们逐一介绍它们.

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

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

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

这意味着如果模块A使用Maven插件(模块B),那么B必须在A之前构建.这样可以处理A的POM中的情况:

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

这意味着如果模块A使用对模块B 具有依赖性的Maven插件,则必须在A之前构建B.这将处理在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>
Run Code Online (Sandbox Code Playgroud)

请注意,此规则在最后一个之后应用,因此即使插件本身也是构建的模块,它也将在之前构建,确保解析依赖项是安全的.

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

这意味着如果模块A声明使用模块B 作为扩展,则必须在A之前构建B.这将处理在A的POM中您将拥有的情况:

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

如果没有应用先前的规则,则顺序是<modules>聚合器项目的POM中的顺序:

<modules>
  <module>A</module>
  <module>B</module>
</modules>
Run Code Online (Sandbox Code Playgroud)

如果没有应用先前的规则,则将在B之前构建A.