Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 654
ziggy Avatar asked May 19 '12 14:05

ziggy


People also ask

Does Maven support multi project build?

As seen in the introduction to the POM, Maven supports project aggregation in addition to project inheritance. This section outlines how Maven processes projects with multiple modules, and how you can work with them more effectively.

How do you create a multi-module project?

POM Aggregator (Parent POM) Let's understand the structure of the multi-module application that we have created. Step 1: Create a Maven Project with the name spring-boot-multimodule. Step 2: Open the pom. xml (parent pom) file and change the packaging type jar to pom.

What is multi-module Maven project?

A multi-module project is built from an aggregator POM that manages a group of submodules. In most cases, the aggregator is located in the project's root directory and must have packaging of type pom. The submodules are regular Maven projects, and they can be built separately or through the aggregator POM.

Can a Maven project have multiple pom files?

Yes you can use Maven Profiles to manage this. Obviously you can tweak this approach to suit your needs however works best.


2 Answers

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.

like image 120
Ryan Stewart Avatar answered Sep 29 '22 18:09

Ryan Stewart


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.

like image 37
artbristol Avatar answered Sep 29 '22 18:09

artbristol