Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the major difference between maven `-f` and `-pl` parameters?

Tags:

maven

When executing mvn test -f file-directory and mvn test -pl project. What is the difference in internal execution of the both ?

like image 940
hemanik Avatar asked Aug 23 '17 16:08

hemanik


People also ask

What is F in Maven?

-f,--file <arg> Force the use of an alternate POM file. -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.

Why Maven takes much time for 1st execution and from 2nd execution it will take less time?

If you have just installed Maven, it may take a while on the first run. This is because Maven is downloading the most recent artifacts (plugin jars and other files) into your local repository. You may also need to execute the command a couple of times before it succeeds.

Which of the following option can be used with a Maven command to use activate a profile?

Profiles can be activated in the Maven settings, via the <activeProfiles> section. This section takes a list of <activeProfile> elements, each containing a profile-id inside. Profiles listed in the <activeProfiles> tag would be activated by default every time a project use it.


1 Answers

From mvn -help

 -f,--file <arg>                        Force the use of an alternate POM
                                        file.

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

Example Usage:

  • -f
    • If you want to build a Maven project but you are running Maven from a directory other than the directory which contains the pom.xml for that project.
    • If (for some reason) your POM file is not named pom.xml
  • -pl
    • If you want to build a Maven build focussing on a sub set of the parent project's sub modules
    • If you want to resume a multiple module Maven build from the point at which a previous build failed

Given this project structure ...

+- tools
| |
| +- build
| |
+- projects
| |
| +- parent
|    |
|    +- pom.xml
|  
| +- childA
|    |
|    +- pom.xml
| +- childB
|    |
|    +- pom.xml

You could ...

  • Build the parent project from the tools/build directory by using -f e.g.
    • cd tools/build; mvn -f ../../projects/parent/pom.xml
  • Build only the childA sub module from the tools/build directory by using -f and -pl e.g.
    • cd tools/build; mvn -f ../../projects/parent/pom.xml -pl parent:childA
  • Build only the childB sub module from the parent directory by using -pl e.g.
    • cd projects/parent; mvn -pl parent:childB
like image 181
glytching Avatar answered Sep 30 '22 13:09

glytching