preface
Yesterday, a reader asked me about my work experience and accidentally raised an interesting question as follows:
The company is developing multiple modules recently. Because of the interdependence between modules, it is very troublesome to package each module. We must package each module according to the dependency relationship.
As anyone who plays Maven knows, all it takes is one command to solve the problem.
dependencies
Suppose there is A multi-module project, the parent project P contains three sub-modules A, B and C, and the three modules have the following dependencies:
- A depends on B and C.
- B depends on C.
Dependency diagram
The pom.xml of the parent project P is as follows:
. <modules> <module>A</module> <module>B</module> <module>C</module> </modules> .....Copy the code
The pom.xml of module A is as follows:
. <dependency> <groupId>xxx.xxxx</groupId> <artifactId>B</artifactId> <version>xxxx</version> </dependency> .....Copy the code
The pom.xml of module B is as follows:
. <dependency> <groupId>xxx.xxxx</groupId> <artifactId>C</artifactId> <version>xxxx</version> </dependency> .....Copy the code
The pom.xml of module C is as follows:
.Copy the code
What would you do?
Now the product needs to go online project A, how should you package it?
The most obvious is to pack them separately and execute the following commands:
mvn clean install C
mvn clean install B
mvn clean package A
Copy the code
The above three modules take turns to pack, at least it takes more than five minutes, don’t you panic?
A batch of panic
Here’s the thing: ALL I need is the following command:
mvn clean package -pl A -am -P test -DskipTests=true
Copy the code
What’s the meaning of this order? ** -p specifies the environment, -dskiptests =true skips the tests, but what are -pl and -**am?
**-pl and -**am
A few parameters you need to know
**-pl and -**am are both important parameters. As follows:
The value is artifactId-am. It is optional to process the dependent modules of the module specified by the PL parameter. – AMD Is optional to process the dependent modules of the module specified by the PL parameter
How’s it going? Does that make sense? Is it a little obscure, ha ha….
what?
Don’t worry, here are a few commands to understand (all in the parent project P root directory).
- mvn clean install -pl A -am
Perform MVN clean Install on parent project P, child module A, and modules B and C on which module A depends.
After the command is successfully executed, modules P, A, B, and C are installed locally.
- mvn clean install -pl C -am
Perform MVN clean install on parent project P and child module C.
After the command is executed successfully, you can see that modules P and C are installed locally.
Module C is “independent” of the other two sub-modules, so modules A and B do not run related commands.
- mvn clean install -pl C -amd
Perform MVN clean install on parent project P, child module C, and modules B** and **C that depend on module C.
After the command is successfully executed, modules P, A, B, and C are installed locally.
- mvn clean install -N
Only the parent project P will be packaged, and its child modules will not perform relevant operations.
How’s that? Through the above command should understand it.
conclusion
As the volume of the project gradually grows, there are more than a few modules above, and the efficiency can be more than doubled by learning the above commands.
The last
Thank you for reading here, the article is inadequate, welcome to point out; If you think it’s good, give me a thumbs up.
Also welcome to pay attention to my public number: programmer Maidong, Maidong will share Java related technical articles or industry information every day, welcome to pay attention to and forward the article!