Define modules list which shall be built in Maven multiproject build
Asked Answered
T

2

6

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:

Is it possible to use -pl option with artifactId?

Tilden answered 17/10, 2014 at 16:29 Comment(3)
Which maven version do you use? how did you call it? How does your pom file look like?Erving
For reference: Maven by Example: "each module element corresponds to a subdirectory of the simple-parent/ directory". Isn't it considered best practice to name projects' directories in accordance with their artifactIds? I'm not aware of any sub-project where this is not the case in our project with 15 top-level projects and hundreds of sub-projects.Prioress
And consider performance. With having to parse the POMs in every sub-directory to check whether the artifactId applies - even if the majority doesn't apply for a certain build. Taking absolute directory names limited to the needed is much faster.Prioress
M
20

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
Melentha answered 18/10, 2014 at 12:54 Comment(2)
What does the l in -pl stand for?Declivity
@Declivity "list", as in "project list". Maven doesn't follow the POSIX convention of having only single letters for short options. So it's not "-p -l", it's just "-pl"Mak
C
7

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
Checkers answered 14/2, 2019 at 19:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.