Maven构建模块故障

时间:2013-08-08 07:06:31

标签: maven multi-module

我正在尝试构建一个包含多个模块的maven项目。所以我希望它们按照pom.xml中给出的顺序构建,但是可以看出构建中的模块的顺序与pom.xml文件中提到的顺序不同。可能是什么原因?

My Maven版本:Apache Maven 3.0.4

2 个答案:

答案 0 :(得分:1)

Maven根据依赖关系决定顺序。因此,如果您有3个子模块:A,B和C,则需要进入每个子模块并使依赖项显式化。例如,如果你转到B的pom.xml并声明它依赖于A和C,maven将以某种随机顺序构建A和C,并在最后构建B.

答案 1 :(得分:1)

在父pom文件中提到的顺序在模块之间没有依赖性崩溃的情况下也是相关的,这意味着如果列表中存在上面的任何模块并且它取决于它下面的模块,那么不会使用POM文件中提到的这种情况,Maven将使用他的大脑,并首先构建其他一些模块需要构建的所有模块。

有关构建订单的更多信息,请查看此questionMaven Spec

来自规格:

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:

    1. project dependency on another module in the build
    2. plugin declaration where the plugin is another modules in the build
    3. plugin dependency on another module in the build
    4. build extension declaration on another module in the build
    5. the order declared in the modules 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.