Maven - How to build multiple Independent Maven projects from one project

倾然丶 夕夏残阳落幕 提交于 2019-11-27 11:36:49

问题


I have 3 maven projects

  • WebComponents
  • DataComponents
  • ServiceComponents

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.

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?

I can probably achieve this by writing a simple batch file that builds every projects but is it possible using Maven?


回答1:


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>

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.




回答2:


If you add an aggregator project in the directory above the three projects that names them as modules (module name = subdirectory name), it will build them without needing any changes in their own POMs. They don't need to reference it as a parent.



来源:https://stackoverflow.com/questions/10665936/maven-how-to-build-multiple-independent-maven-projects-from-one-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!