Maven build lifecycle details
What is the build lifecycle
A construction life cycle is a sequence of phases. Each of these construction life cycles is defined by a different list of construction phases, where the construction phase represents the phase in the life cycle.
For example, the default lifecycle includes the following phases (Note: here is a simplified phase for a complete list of lifecycle phases):
Validate - verify that the project is correct and all necessary information is available. Compile - compile the source code of the project. Test - test the compiled source code using the appropriate unit test framework. These tests should not require the code to be packaged or deployed. Package - use the compiled code in its assignable format (such as jar). Verify - perform any checks on the results of the integration test to ensure that the quality standards are met. Install - install the package into the local repository as a dependency deployment for other projects locally (deploy) - complete in the build environment, copy the final package to the remote repository for sharing with other developers and projects. Each phase defines the order in which the goals are executed. The phases here are part of the life cycle.
For example, a typical Maven build life cycle is composed of the following stages:
When you need to execute a goal before or after a specific stage, you can use pre and post to define the goal.
When Maven starts the construction project, the target of each phase registration will be executed in the order of the defined phase sequence. Maven has the following three standard life cycles:
clean default(or build) site
A goal represents a specific task that helps build and manage the project. It may be bound to 0 or more build phases. Targets that are not bound to any build phase can be called and executed directly outside the build lifecycle.
The order of execution depends on the order in which the target and build phases are invoked. For example, consider the following command. The clean and package parameters are the build phase, and dependency: copy dependencies is a target.
Here, the clean phase will be executed first, then the dependency: copy dependencies target will be executed, and finally the package phase will be executed.
Clean life cycle when we execute the MVN post clean command, Maven calls the clean life cycle, which contains the following stages.
pre-clean clean post-clean
Maven's clean target (clean: clean) is bound to the clean phase of the clean life cycle. Its clean: clean target deletes the build output by deleting the build directory. Therefore, Maven deletes the build directory when the MVN clean command is executed.
We can modify the operation behavior of this part by defining goals at any stage of the clean life cycle above.
In the following example, we add the Maven ant run plugin: run target to the pre clean, clean, and post clean phases. In this way, we can display text information at all stages of the clean life cycle.
We have created a POM. Com in the C: \ MVN \ project directory XML file.
Now open the command console and jump to POM XML directory, and execute the following MVN command.
Maven will begin processing and displaying all phases of the clean lifecycle.
You can try to modify the MVN clean command to display pre clean and clean without doing anything in the post clean phase.
Default (or build) life cycle, which is the main life cycle of Maven and is used to build applications. It includes the following 23 stages.
There are some important concepts related to Maven life cycle that need to be explained:
When a phase is called by Maven command, such as MVN compile, only the phases before and including the phase will be executed.
Different Maven targets will be bound to different Maven life cycle stages according to the type of package (jar / war / ear).
In the following example, we add the Maven ant run plugin: run target to a part of the build lifecycle. In this way, we can display the text information of the life cycle.
We have updated pom.com in C: \ MVN \ project directory XML file.
Now open the command console and jump to POM XML and execute the following MVN command.
Maven will start processing and displaying the phases of the build life cycle up to the compilation phase.
Site lifecycle Maven site plug-ins are generally used to create new report documents, deploy sites, etc.
Phase:
Pre site site post site deploy in the following example, we add the maven antrun plugin: run target to all stages of the site life cycle. In this way, we can display all text information of the lifecycle.
We have updated pom.com in C: \ MVN \ project directory XML file.
Now open the command console and jump to POM XML and execute the following MVN command.
Maven will begin processing and displaying the various stages of the site lifecycle up to the site stage.
The above is all about the detailed introduction of Maven construction life cycle in this article. I hope it will be helpful to you. Welcome to: detailed explanation of Maven management springboot profile, Maven learning - first glimpse of the path, three methods of parsing using Maven to run Java main, etc. if there are any shortcomings, please leave a message and point out. Thank your friends for their support to this site.