在本地构建时自动重建依赖项目 [英] Rebuild dependent projects automatically when building locally
问题描述
我有几个Maven项目,它们共享一个共同的父对象,如下所示:
I have several Maven projects which share a common parent as following:
project-parent
project-1
project-2: includes project-1
project-3: includes project-2
在此,例如,project-3
的依赖关系为project-2
,project-2
的依赖关系为project-1
.
Here, project-3
has project-2
in its dependencies and project-2
has project-1
in its dependencies, as an example.
当我将项目推送到git
时,Jenkins
会自动重建为从属项目.例如,当我按project-3
时,将重新构建project-2
.因此,project-1
也将被重建.发生这种情况是因为詹金斯(Jenkins)了解依赖图.
When I push a project to git
, Jenkins
automatically rebuilds to dependent projects. For example, when I push project-3
, project-2
will be rebuilt. Because of that, project-1
will be rebuilt as well. This happens because Jenkins has knowledge about the dependency graph.
但是,当我在开发计算机上本地构建project-3
时,我必须记住还要重建project-2
(和project-1
).
However, when I build project-3
locally on my development machine, I have to remember to rebuild project-2
(and project-1
) as well.
我可以在父项目中添加一个<modules>...</modules>
部分,然后简单地重建父项目.这将重建整个项目,包括所有子项目.但是,我不想这样做,因为有很多项目,其中一些项目需要大量的时间来构建.
I could add a <modules>...</modules>
section to the parent project and simply rebuild the parent project. This will rebuild the whole project, all child projects included. However, I would rather not do that, as there are a lot of projects and some of them require a lot of time to build.
因此,我想构建一个项目(我正在研究的一个项目),然后以某种方式自动(或方便地)重建所有相关项目,类似于Jenkins的行为.基本上,我想在开发机器上本地实现Jenkins行为.这可能吗?
So I want to build one project (the one I'm working on) and somehow automatically (or conveniently) rebuild all dependent projects, similar to the Jenkins behavior. Basically, I want to achieve the Jenkins behavior locally on my development machine. Is this possible?
推荐答案
您可以从父项目执行以下命令(假设<module>...</module>
中有my-child-module:
You can execute the following command from your parent project (assuming you have the my-child-module in the <module>...</module>
:
mvn clean install -pl my-child-module -am
此命令将构建项目my-child-module
及其依赖项.
This command will build the project my-child-module
and its dependencies.
-pl,--projects
构建指定的反应堆项目,而不是所有项目
-pl, --projects
Build specified reactor projects instead of all projects
-am,--also-make
如果指定了项目列表,则还要构建列表所需的项目
-am, --also-make
If project list is specified, also build projects required by the list
-amd,--also-make-depends 如果指定了项目列表,则还要构建依赖于列表中项目的项目
-amd, --also-make-dependents If project list is specified, also build projects that depend on projects on the list
这篇关于在本地构建时自动重建依赖项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!