Maven - skip parent project build

前端 未结 5 1198
轮回少年
轮回少年 2020-12-06 16:30

I know it\'s mauvais ton to ask twice in a single day but here\'s another Maven puzzler:

I have a parent POM which defines 5 modules (5 subprojects). Since

5条回答
  •  天涯浪人
    2020-12-06 16:54

    What is wrong by building the parent?

    In fact, in Maven, there are two different concepts (which are generally used at the same time):

    • The parent POM
    • The modules aggregation

    The first one is a definition of everything that is common with all the children. You define a parent as a pom-packaged project, and you can install it in your repository.

    When you build a child of this parent, Maven2 will retrieve this parent to merge the parent pom with the child pom. You can have a look to the entire pom.xml by running the command mvn help:effective-pom.

    In this case, the parent pom will not be built, it will just be retrieved from the repository.

    The second case is a project that contains a modules list of sub-projects. The principle is that every command that you run on this project will also be run on all the sub-modules. The order of the modules will be defined by the Reactor, which will look at inter-modules dependencies to find which module must be built before the others. If there are no dependencies, then it will take the list of the modules as they are defined in the parent pom.xml.

    In this case, if you run a command on the root project, Maven2 will first built the root project, and then the sub-modules. You cannot skip the creation of the root project.


    Edit, thanks to RichSeller comment

    A complete explanation of the differences between multi-modules (aggregation project) and inheritance (parent project) can be found in the Maven book, here.

提交回复
热议问题