Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define modules list which shall be built in Maven multiproject build

I would like to use Maven -pl option to define which specific modules shall be included into reactor. The option works if list of module's paths is provided. Unfortunately, providing module's artifactIds is not working at all.

Sonatype: Maven: The Complete Reference docs are using multiproject example where directories names are matching artifactIds:

  • Using Advanced Reactor Options

Is it possible to use -pl option with artifactId?

like image 247
Piotr Oktaba Avatar asked Oct 17 '14 16:10

Piotr Oktaba


People also ask

What is multi module project in Maven?

Maven's 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.

How to build submodules in Maven?

Now, the submodules are regular Maven projects, and they can be built separately or through the aggregator POM. By building the project through the aggregator POM, each project that has packaging type different than pom will result in a built archive file.

How does Maven know what projects to build?

Note: 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). Maven will examine the list of projects and walk down the dependency tree, finding all of the projects that it needs to build.

Is there a command to see all the modules in Maven?

Not sure if there is a command for that , but you can either view the pom file of your profile or the maven site generated out of the build to understand the hierarchy. Also at the end of the build there will be a list of modules which have been built , so perhaps a simple "mvn clean" will be enough to reveal all the modules.


2 Answers

Yes, it's possible to do this. Take a look at mvn --help:

 -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.

Note in particular that an artifactId without a leading groupId still has a leading colon.

So, for example in a case where the artifactId is the same as the directory name, these three lines would all refer to the same module in Maven:

  • mvn -pl maven-core
  • mvn -pl :maven-core
  • mvn -pl org.apache.maven:maven-core
like image 119
Joe Avatar answered Sep 23 '22 19:09

Joe


mvn seems to take the list you provide with -pl to the heart and not build any dependencies automatically.

So in addition to Joe's answer: If the project/module you're trying to build depends on other modules then you can ask mvn to build them as well with -am.

-am,--also-make
       If project list is specified, also build projects required by the list

If project list is specified = if -pl option is used

So examples become:

  • mvn -pl maven-core -am
  • mvn -pl :maven-core -am
  • mvn -pl org.apache.maven:maven-core -am
like image 25
Kashyap Avatar answered Sep 23 '22 19:09

Kashyap