My maven project structure is as below
Project A
pom.xml
- ProjectB
pom.xml
- ProjectC
pom.xml
- ProjectD
pom.xml
- ProjectY
pom.xml
By using maven reactor options i can
clean install -pl projectB
or clean install -pl projectY
But while trying to build the second level child modules using clean install -pl projectC
, maven throws
org.apache.maven.MavenExecutionException: Could not find the selected project in the reactor: projectC
how to build the second level+ child modules using maven reactor options
The reactor is the part of Maven that allows it to execute a goal on a set of modules. As mentioned in the Maven 1. x documentation on multi-modules builds (the reactor concept was already there in Maven 1.
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.
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.
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.
The Reactor. The mechanism in Maven that handles multi-module projects is referred to as the reactor. This part of the Maven core does the following: Collects all the available modules to build. Sorts the projects into the correct build order. Builds the selected projects in order.
The -rf or --resume-from option can come in handy if you want to tell the Maven Reactor to resume a build from a particular project.
If you wanted to run a portion of the larger build, you would use the-pl or --projects option with the-am or --also-make option. When you specify a project with the-am option, Maven will build all of the projects that the specified project depends upon (either directly or indirectly).
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. The mechanism in Maven that handles multi-module projects is referred to as the reactor.
From the documentation for the -pl
option it states the following:
-pl,--projects <arg> Comma-delimited list of specified
reactor projects to build instead
of all projects. A project can be
specified by [groupId]:artifactId
or by its relative path.
The important part for you is: "or by its relative path".
So to build projectC
, you simply need to refer to it by its relative path (projectB/projectC
). So the command you need is:
mvn clean install -pl projectB/projectC
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With