4

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:

http://books.sonatype.com/mvnref-book/reference/_using_advanced_reactor_options.html

Is it possible to use -pl option with artifactId?

Kashyap
  • 12,510
  • 8
  • 55
  • 90
Piotr Oktaba
  • 735
  • 4
  • 14
  • 1
    Which maven version do you use? how did you call it? How does your pom file look like? – khmarbaise Oct 17 '14 at 18:41
  • For reference: [Maven by Example](http://books.sonatype.com/mvnex-book/reference/multimodule-sect-simple-parent.html): _"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. – Gerold Broser Oct 17 '14 at 19:48
  • 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. – Gerold Broser Oct 17 '14 at 19:54

2 Answers2

11

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
Joe
  • 23,380
  • 9
  • 61
  • 75
1

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
Kashyap
  • 12,510
  • 8
  • 55
  • 90