Maven多模块项目的构建顺序? [英] Build order of Maven multimodule project?

查看:47
本文介绍了Maven多模块项目的构建顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况是,我有两个结构相同的Maven多模块项目:

<前>家长- 模块 1- 模块 2

当我构建项目 1 时,我看到首先构建了 parent(顺序是 parent->module1->module2).但是对于项目 2,最后构建了父级(顺序是 module1->module2->parent).为什么这两个项目的构建顺序不同?此外,如何手动控制构建顺序?

更新 1:
两个父项目都是没有源代码的简单POM项目,所以我无法按照依赖图解释构建顺序.

更新 2:
除了 GAV 和子模块名称外,父 POM 是相同的:

<前><?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>parent-group-id</groupId><artifactId>parent-artifact-id</artifactId><version>父版本</version><packaging>pom</packaging><name>parent-name</name><模块><module>module-1</module><module>module-2</module></模块></项目>

解决方案

构建顺序由 Maven reactor 决定,这是一种通过对项目进行排序来自动确保多模块构建的正确构建顺序的机制.

有关其工作原理,请参阅官方文档.

它说:

<块引用>

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

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

您无法手动控制构建顺序.如果您想更改顺序,您必须对影响反应器排序顺序的项目进行更改.

The situation is, I have two Maven multimodule projects with the same structure:

Parent
    - Module 1
    - Module 2

When I build project 1, I see that parent is built first (order is parent->module1->module2). However for project 2, parent is built at last (order is module1->module2->parent). Why are the two projects have different build orders? Furthermore, how can I manually control the build order?

Update 1:
Both parent projects are simple POM projects without source code, so I can't explain the build order as per the dependency graph.

Update 2:
The parent POMs are the same except the GAV and child module names:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>parent-group-id</groupId>
    <artifactId>parent-artifact-id</artifactId>
    <version>parent-version</version>
    <packaging>pom</packaging>
    <name>parent-name</name>
    <modules>
        <module>module-1</module>
        <module>module-2</module>
    </modules>
</project>

解决方案

The build order is determined by the Maven reactor which is a mechanism that automatically ensures correct build order for multimodule builds by sorting the projects.

See the official documentation for how it works.

It says:

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)

You can't manually control the build order. If you want to change the order you have to make changes to your project that influence the reactor sort order.

这篇关于Maven多模块项目的构建顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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