The life cycle of Maven (v)

Source: Internet
Author: User

One important reason for Maven's strength is that it has a well-developed life cycle model (lifecycle) that can be understood in two ways, first, as the name implies, every step of running MAVEN is defined by it, This predefined default behavior makes it easy for us to use MAVEN, and each step of ant is defined by you by hand. Second, this model is a standard, in different projects, using MAVEN interface is the same, so do not have to carefully understand the construction of each project, in general,mvn clean install such command is generic. I think the experience of many projects must be absorbed, and Maven can define such a perfect model.

MAVEN has three sets of independent life cycles, please note that this is said to be "three sets", and "mutual independence", beginners easily to the Maven life cycle as a whole, not actually. These three sets of lifecycles are: clean Lifecycle some cleanup before making a real build.
The core part of the Default Lifecycle build, compile, test, package, deploy, and so on.
Site Lifecycle generates project reports, sites, and publishing sites.

Again, I emphasize that they are independent, you can simply call clean to clear the working directory, just call site to build the site. Of course you can also run mvn clean install site to run all of these three sets of lifecycles directly.

Knowing the approximate use and correlation of each set of life cycles, to look at each set of life cycles in detail, clean and site are relatively simple to explain first.

Each set of lifecycles consists of a set of stages (Phase), and the commands we normally enter at the command line always correspond to a specific stage. For example, running mvnclean, this clean is a phase of the clean life cycle. A bit around. Know that there is a clean life cycle and there is a clean phase. The clean life cycle consists of three phases: Pre-clean performs some work that needs to be done before clean removes all previous build-generated files Post-clean performs some work that needs to be done immediately after clean

The clean in mvn Clean is the clean in the above, and in one life cycle, all phases before it run, that is to say,mvn Clean is equivalent to mvn Pre-clean Clean, if we run mvn post-clean, then Pre-clean,clean will be run. This is a very important rule for MAVEN, which can greatly simplify the input of the command line.

Here's a look at each phase of the site lifecycle: Pre-site performs some work that needs to be done before the site document is generated, site-generated project Post-site performs some work that needs to be done after the site document is built, and prepares for deployment site-d Eploy deploy the generated site document to a specific server

The site phase and the Site-deploy phase are often used here to generate and publish Maven sites, which is a pretty powerful feature of Maven, and the manager prefers that documents and statistics are generated automatically and beautifully.

Finally, take a look at Maven's most important default life cycle, where most of the work takes place in this life cycle, where I only explain some of the more important and common stages: Validate Generate-sources process-sources Generate-resources process-resources Copy and process the resource files to the target directory, ready to package. Compile the source code of the compiled project. Process-classes generate-test-sources process-test-sources
Generate-test-resources process-test-resources Copy and process the resource file to the target test directory. Test-compile Compile the test source code. Process-test-classes Test runs the tests using the appropriate unit test framework. These test codes are not packaged or deployed. The Prepare-package package accepts compiled code that is packaged into a published format, such as a JAR. Pre-integration-test integration-test post-integration-test Verify install installs the package to the local warehouse for other projects to rely on. Deploy copies the final package to a remote repository for other developers to share with the project.

Basically, we can guess the purpose of each stage by name, and for the explanations of the other stages, please refer to the http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

Remember, when you run any stage, all the stages in front of it will be run, which is why when we run mvn install , the code is compiled, tested, packaged.

In addition, MAVEN's plug-in mechanism relies entirely on the life cycle of maven, so understanding the lifecycle is critical, and in subsequent articles I'll explain the Maven plugin mechanism further.


Article turned from: http://juvenshun.iteye.com/blog/213959

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.