Maven-跳过父项目构建 [英] Maven - skip parent project build

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

问题描述

我知道这是 mauvais ton 一天问两次,但这是另一个Maven难题:

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

我有一个父POM,它定义了5个模块(5个子项目).由于每个模块都是以完全相同的方式执行的,因此我将<profile><build>部分拉到父POM中以消除重复的代码.现在-如果我从每个模块分别执行构建,则可以正常工作,但是,如果我想一次构建所有模块并移至父目录,则会出错,因为Maven尝试执行的第一件事就是父项目本身:

I have a parent POM which defines 5 modules (5 subprojects). Since each module is executed in exactly the same way I pull <profile><build> section into the parent POM to get rid of the duplicate code. Now - if I execute build individually from each module it works, however if I want to build all modules at once and move to the parent directory I got error since the very first thing Maven tries to execute is the parent project itself:

mvn package -P release
[INFO] Scanning for projects...
[INFO] Reactor build order:
[INFO]   DWD Parent project
[INFO]   Projects

在此之后构建失败,因为exec插件试图执行不存在的内容.从输出来看,很明显Reactor插件正在驱动构建,但是如何配置Reactor跳过父级呢?

After that build fails because exec plugin tries to execute something that is not there. Looking at the output it is pretty obvious that reactor plugin is driving the build but how can I configure reactor to skip the parent?

P.S.为避免混淆-我试图禁止在父级上执行配置文件,并在same构建期间对子级启用配置文件

P.S. To prevent confusion - I'm trying to suppress profile execution on parent and enable it on child during the same build

推荐答案

构建父级有什么问题?

实际上,在Maven中,有两个不同的概念(通常同时使用):

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

  • 父POM
  • 模块聚合

第一个是所有孩子共同的事物的定义.您将父项定义为pom打包项目,然后可以将其安装在存储库中.

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.

构建此父级的子级时,Maven2将检索该父级,以将父级pom与子级pom合并.您可以通过运行命令mvn help:effective-pom来查看整个pom.xml.

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.

在这种情况下,将不会构建父pom,而只会从存储库中检索它.

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

第二种情况是一个包含modules子项目列表的项目.原理是,在此项目上运行的每个命令也将在所有子模块上运行.模块的顺序将由Reactor定义,Reactor将查看模块间的依赖关系,以找出必须先构建哪个模块.如果没有依赖关系,则将采用父pom.xml中定义的模块列表.

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.

在这种情况下,如果您在根项目上运行命令,则Maven2将首先构建根项目,然后构建子模块.您不能跳过根项目的创建.

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.

编辑,感谢RichSeller的评论

关于多模块(聚合项目)和继承(父项目)之间差异的完整解释可以在Maven的书中找到,

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

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

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