maven ---- Analysis of project package build log

Posted by ThE_eNd on Fri, 17 Dec 2021 22:51:24 +0100

maven ---- log analysis during project packaging and construction

Purpose of this paper

  last article, maven ---- relying on Mediation Mechanism.
  when we execute the mvn clean install command or when idea executes clean install, we will see a pile of logs printed on the console, and finally the printed jar package appears under the target folder of the project.
  I haven't seen what the printed logs did before. Here's a summary of the process.

text

  in fact, we should first introduce Maven's other two core concepts, life cycle and plug-in. But I think it's the reverse. First, let's take a look at what we often use the command clean install does during execution.

1. Construction basis

   after clean install, the project will execute many things. The specific implementation content will be based on the implementation of the plug-in. Therefore, in the log, you will see a lot of things with XXX plugin, and the execution sequence and scope of plug-ins are based on the definition of life cycle.
  where did these plug-ins come from? Basically three places

  1. Current project POM Defined in the corresponding < plugins > tag in XML.
  2. POM of parent project It is defined in the corresponding < plugins > tag in XML and inherited by the current project.
  3. Root POM, i.e. / lib / Maven model builder XXX. Corresponding to Maven installation package jar/org/apache/maven/pom-4.0. 0.xml.

2. Specific log

   when the project is built, these plug-ins will be implemented according to the definition of life cycle. Below is the log of my project packaging. Refer to the following:

 /**1. Scan items**/
[INFO] Scanning for projects...
[INFO]  
 /**2. Start building project**/
[INFO] ------------------------------------------------------------------------
[INFO] Building znxd-base-master 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
 /**3. Using the maven clean plugin plug-in, first clear the target file content of the maven project**/
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ znxd-base-master ---
[INFO] Deleting E:\znworkspace\znxd-base-master\target
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ znxd-base-master ---
 /**4. Use the Maven resources plugin to copy the files in src/main/resources to target/classes**/
[INFO] Using 'UTF-8' encoding to copy filtered resources.
 /**5. Copying 21 files under src/main/resources**/
[INFO] Copying 21 resources
[INFO] 
 /**6. Use the Maven compiler plugin plug-in to compile the file under src/main/java**/
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ znxd-base-master ---
[INFO] Changes detected - recompiling the module!
 /**7. Compiling 102 files under src/main/java. Copy the compiled files to / target/classes**/
[INFO] Compiling 102 source files to E:\znworkspace\znxd-base-master\target\classes
 /**8. The following are some warnings during compilation**/
[INFO] /E:/znworkspace/znxd-base-master/src/main/java/com/agri/utils/Okhttp3Utils.java: E:\znworkspace\znxd-base-master\src\main\java\com\agri\utils\Okhttp3Utils.java Used or overwritten obsolete API. 
[INFO] /E:/znworkspace/znxd-base-master/src/main/java/com/agri/utils/Okhttp3Utils.java: For more information, Please use -Xlint:deprecation Recompile.
[INFO] /E:/znworkspace/znxd-base-master/src/main/java/com/agri/framework/web/controller/user/SysUserController.java: Some input files use unchecked or unsafe operations.
[INFO] /E:/znworkspace/znxd-base-master/src/main/java/com/agri/framework/web/controller/user/SysUserController.java: For more information, Please use -Xlint:unchecked Recompile.
[INFO] 
 /**9. Then use the Maven resources plugin to copy the files in src/test/resources to target / test classes**/
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ znxd-base-master ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
 /**10. Because there is no src/test/resources folder in my project, I am prompted to skip**/
[INFO] skip non existing resourceDirectory E:\znworkspace\znxd-base-master\src\test\resources
[INFO] 
 /**11. Then use the Maven compiler plugin plug-in to compile the file under src/test/java**/
[INFO] --- maven-compiler-plugin:3.3:testCompile (default-testCompile) @ znxd-base-master ---
[INFO] No sources to compile
[INFO] 
 /**12. Use the Maven surefire plugin plug-in to run the unit test classes that meet the rules under src/test/java (5.1 unit test matching rules below)**/
[INFO] --- maven-surefire-plugin:2.20.1:test (default-test) @ znxd-base-master ---
[INFO] No tests to run.
[INFO] 
 /**13. Use the Maven jar plugin plug-in to package the project into jars**/
[INFO] --- maven-jar-plugin:3.1.2:jar (default-jar) @ znxd-base-master ---
[INFO] Building jar: E:\znworkspace\znxd-base-master\target\znxd-base-master.jar
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.2.5.RELEASE:repackage (repackage) @ znxd-base-master ---
[INFO] Replacing main artifact with repackaged archive
[INFO]
 /**14. The Maven install plugin is used for installation. Generally, the install plugin is installed in the local warehouse and target folder. If you want to install it on a private server, you can see the link below (mentioned later)**/
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ znxd-base-master ---
/**15.Install the project into your local warehouse**/
    [INFO] Installing E:\znworkspace\znxd-base-master\target\znxd-base-master.jar to d:\mavenJarOnline\com\znxd\znxd-base-master\1.0-SNAPSHOT\znxd-base-master-1.0-SNAPSHOT.jar
[INFO] Installing E:\znworkspace\znxd-base-master\pom.xml to d:\mavenJarOnline\com\znxd\znxd-base-master\1.0-SNAPSHOT\znxd-base-master-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 42.290 s
[INFO] Finished at: 2021-07-16T02:29:24-03:00
[INFO] Final Memory: 62M/703M
[INFO] ------------------------------------------------------------------------

3. Main plug-ins involved

  the main plug-ins involved in the whole process are as follows:

  1. Maven resources plugin: copy the files in src/main/resources and src/test/resources directories to target.
  2. Maven compiler plugin: copy the files in src/main/java and src/test/java directories to target.
  3. Maven surefire plugin: run unit tests under src/test/java. When the class in this directory is named, if * * / test * * java,**/*Test.java,**/*TestCase. According to Java rules, these classes will be executed during project construction. Therefore, pay attention to whether these test classes can be executed normally during project construction, otherwise an error will be reported.
  4. Maven install plugin: install the jar package into the local repository.

Topics: Maven