Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven -pl !<module> doesn't exclude submodules of <module> from the build

Tags:

maven

maven-3

I use maven 3.2.3.

I have a multi-module project with three levels of nested modules. I want to build all first-level modules(with their submodules) except one. For this task I tried to use -pl option and specifying the module I want to exclude from the build using !moduleName.

What I have in result is that the specified module is excluded from the build, BUT submodules of that module are not.

Is it an expected behaviour and I should explicitly exclude all the nested submodules as well?

like image 952
Dmitry Klochkov Avatar asked Feb 06 '15 14:02

Dmitry Klochkov


People also ask

How to exclude specific dependency in Maven?

Open the dependency POM and find the transitive dependency you want to exclude. Copy groupId and artifactId . In your project POM, underneath your active dependency, enter exclusions and using code completion paste the copied info of the dependency you want to exclude.

What is Maven dependency exclusion?

Exclusions are set on a specific dependency in your POM, and are targeted at a specific groupId and artifactId. When you build your project, that artifact will not be added to your project's classpath by way of the dependency in which the exclusion was declared.

Why multi-module Spring Boot?

One of the best benefit of using Spring Boot based multi-module project is the ability to define the global dependencies at one place and let the child module re-use these configurations without duplicating it. The interesting part of this pom. xml is the <parent> tag.

What is Maven multi-module 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.


1 Answers

The short answer is: yes it is expected behavior.

The feature request that documents this change (allowing you to use !moduleName to exclude a specific module from the build) is documented in issue MNG-5230.

In that request someone specifically asks for the functionality you are looking for:

how about excluding nested modules? I tried the new feature and it seems as though, when a top module is excluded, its nested modules are not.

and the answer there is:

Nested modules are not excluded by parent module.

So looks like you'll have to list them all individually.

If you are always excluding the same modules you could predefine this list in a profile that is either activated or deactivated as required. Details of this can be seen in this answer: https://stackoverflow.com/a/5542779/1570834

like image 127
DB5 Avatar answered Oct 22 '22 22:10

DB5