Maven - 如何从一个项目构建多个独立的 Maven 项目 [英] Maven - How to build multiple Independent Maven projects from one project
问题描述
我有 3 个 Maven 项目
I have 3 maven projects
- Web 组件
- 数据组件
- 服务组件
当我构建每个项目时,我必须进入每个文件夹并在每个项目上运行 mvn clean install.
When i build each of the projects i have to go into each folder and run mvn clean install on each of the projects.
我研究了多模块项目,我看到的大部分资源都表明我必须对现有项目的结构进行更改.
I have looked into multi module projects and most of the resources i see suggest that i have to make a change to the structure of my existing projects.
是否有可能有一个新项目来构建每个独立的项目,而我不必对现有项目中的任何内容(包括它们各自的 pom 文件)进行任何更改?
Is it possible to have a new project that will build each of the independent projects without me having to make any changes to anything in the existing project including their individual pom files?
我可能可以通过编写一个构建每个项目的简单批处理文件来实现这一点,但是否可以使用 Maven?
I can probably achieve this by writing a simple batch file that builds every projects but is it possible using Maven?
推荐答案
您正在寻找没有继承的Maven聚合一>.如参考页面所示,您只需创建一个新的 POM,其包装为pom"并且具有模块"列表.模块是另一个 Maven 项目的相对路径:
You're looking for Maven aggregation without inheritance. As shown in the referenced page, you just create a new POM whose packaging is "pom" and which has a list of "modules". A module is a relative path to another Maven project:
<project>
...
<packaging>pom</packaging>
...
<modules>
<module>foo</module> <!-- module is in a subdirectory of this project -->
<module>../bar</module> <!-- module is a sibling to this project -->
<module>../../../other-projects/baz</module> <!-- somewhere else entirely -->
</modules>
</project>
构建此类 pom 时的默认行为(称为聚合器")是构建所有模块,就像您在每个模块目录中使用相同参数执行 Maven 一样.
Default behavior when building such a pom--known as an "aggregator"--is to build all of the modules as if you'd executed Maven in each module directory with the same arguments.
这篇关于Maven - 如何从一个项目构建多个独立的 Maven 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!