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

问题描述

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



     - 模块1
     - 模块2

当我建项目1项,我看到父母先建(顺序为父 - > module1->模块2 )。然而,对于项目2项,父终于建成(顺序为 module1-> module2->父)。为什么这两个项目有不同的建造顺序?此外,我怎么能手动控制生成顺序?

更新1:结果
两家母公司的项目是没有源$ C ​​$ C简单的POM项目,所以我无法解释构建顺序按依赖关系图。

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


< XML版本=1.0编码=UTF-8&GT?;
<项目的xmlns =htt​​p://maven.apache.org/POM/4.0.0的xmlns:XSI =htt​​p://www.w3.org/2001/XMLSchema-instanceXSI:=的schemaLocationHTTP: //maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">
    < modelVersion> 4.0.0< / modelVersion>
    <&的groupId GT;父组ID< /的groupId>
    <&的artifactId GT;家长神器-ID< / artifactId的>
    <&版GT;亲子版< /版本>
    <包装和GT; POM< /包装>
    <名称>父名< /名称>
    <模块>
        <&模块GT;模块1 LT; /模块>
        <&模块GT;模块-2'; /模块>
    < /模块>
< /项目>


解决方案

在一个较高的水平,构建顺序是基于模块依赖关系图的。

编辑:问题要问你。据我所知,项目1包含两个模块也是如此项目2。但在做项目2个明确的模块声明父POM作为父母?我在想,也许你​​的项目1模块显式声明父POM,以及项目2模块没有。这将意味着在项目2父是不是真的在所有父,因此不具有模块之前建造。这是我的猜测反正。

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>
解决方案

At a high level, the build order is based on a topological sort of the module dependency graph.

EDIT: Question for you. I understand that project 1 contains two modules and so does project 2. But do the modules in project 2 explicitly declare the "parent" pom as a parent? I'm thinking that perhaps your project 1 modules explicitly declare the parent pom, and the project 2 modules don't. Which would mean that the project 2 "parent" isn't really a parent at all and therefore doesn't have to be built before the modules. That's my guess anyway.

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

08-06 08:18