Maven detailed life cycle and plugins (i)

Source: Internet
Author: User

MAVEN is an excellent project management tool that can help you manage your compilations, reports, documents, and more.


the life cycle of Maven:

The life cycle of MAVEN is abstract and it does not do any work by itself. The actual work is done by "plugins".

Each of the build steps of Maven can bind one or more plug-in behaviors, and Maven writes and binds the default plug-in for most of the build steps.


Three sets of life cycles:

Clean, default, site

Clean: The main purpose is to clear the project

Pre-clean: Perform some work that needs to be done before cleaning up

Clean: Cleans up the last build generated file

Post-clean: Perform some cleanup work that needs to be done

default: Defines all the steps that are required to perform a real build, which is the most central part of the life cycle

Validate

Initialize

Generate-sources

process-sources: Processes the project master resource file. In general, after working on variable substitution for the contents of the Src/main/resources directory, copy to the main classpath directory of the project output

Generate-resources

Process-resources

compile: Compile the main source code of the project. In general, it is the compilation of Java files in the Src/main/java directory into the main classpath directory of the project output

Process-classes

Generate-test-sources

process-test-sources: Process Project test resource files. In general, after working on variable substitution for the contents of the Src/test/resources directory, copy to the test classpath directory of the project output

Generate-test-resources

Process-test-resources

test-compile: Compile the test code of the project, in general, compile the Java file in the Src/test/java directory into the test classpath directory of the project output

Process-test-classes

Test : Run the test using the Unit test framework, the testing code will not be packaged or deployed

Prepare-package

Package: Accepts compiled code and packages it into a published format, such as a jar

Pre-integration-test

Integration-test

Post-integration-test

Verify

Install: Installs the package to the MAVEN local repository for use by other local MAVEN projects

Deploy: Copy the final package to the remote repository for use by other developers and MAVEN projects

Site lifecycle: Build and publish project sites, and Maven can automatically generate sites based on the information contained in the POM

Pre-site: Perform some work that needs to be done before building the project site

Site: Build Project Site Documentation

Post-site: Perform some work that needs to be done after building the project site

Site-deploy: Publish the resulting project site to the server


Each phase of the MAVEN lifecycle is interdependent, and when the user calls clean, the Pre-clean and clean phases are executed sequentially, without touching any stage of the default.


Execution at various stages of the complex call and life cycle in the command line:

From three examples to illustrate:

1. $MVN Test: This command invokes the test phase of the default life cycle. The actual execution phase is the validate of the default life cycle to all stages of test

2. $MVN clean Install: This command invokes the clean phase of the clean life cycle and the install phase of the default life cycle. The actual execution is the Pre-clean of the clean life cycle, the clean phase, and the validate of the default life cycle to all phases of the install. This command combines two lifecycles and is a good practice to clean up your project before you perform a real project build.

3. $MVN Clean Deploy Site-deploy: This command invokes the clean phase of the clean life cycle and the Deploy phase of the default life cycle, as well as the site-deploy phase of the site life cycle. The actual implementation is the Pre-clean of the clean life cycle, all phases of the clean phase and the default life cycle, and all phases of the site life cycle.


Maven's plugin

MAVEN's core bundle is less than 3MB in size, and Maven downloads and uses plugins when needed, and for the plug-in itself, it can do multiple tasks in order to reuse the code. MAVEN's lifecycle is tied to plug-ins to accomplish actual build tasks. Specifically, the phase of the lifecycle is tied to the target of the plug-in to accomplish a specific build task.


Built-in bindings

MAVEN binds many plug-in targets at the core for some major life cycle phases

The binding relationship between the clean life cycle phase and the plug-in target

life cycle Phase plug-in target
Pre-clean
Clean Maven-clean-plugin:clean
Post-clean

The binding relationship between the site life cycle phase and the plug-in target

life cycle Phase plug-in target
Pre-site
Site Maven-site-plugin:site
Post-site
Site-deploy Maven-site-plugin:deploy


Default life cycle and built-in plug-in binding relationships and specific tasks (package type: jar)

life cycle Phase plug-in target Perform Tasks
Process-resources Maven-resources-plugin:resources Copy the master resource file to the main output directory
Compile Maven-compile-plugin:compile Compiling the main code to the main output directory
Process-test-resources Maven-resources-plugin:testrresources Copy the test resource file to the test output directory
Test-compile Maven-compiler-plugin:testcompile Compiling test code to test output directory
Test Maven-surefire-plugin:test Executing test Cases
Package Maven-jar-plugin:jar Create a project jar package
Install Maven-install-plugin:install To install the project output artifacts to the local warehouse
Deploy Maven-deploy-plugin:deploy Deploy project output artifacts to remote warehouses



filial piety: The filial piety that should be done as an ordinary person.

The sign of true filial piety is that parents eat well, sleep at ease. I often say, filial piety is to worship and, for example, you are very filial parents, but you and your spouse to divorce, let parents worry, then you filial piety is not complete, only solve the parents worry, is true filial piety. Again, you are very filial piety, but, your family-law, then you can worship, can not next and, not really filial piety. married daughter-in-law if can be more filial-shouting truth filial piety, by her husband respect, similarly, son-in-laws to more filial-father-in-law, so that can make his wife feel warm.

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.