Maven Life cycle

Source: Internet
Author: User

a complete project build typically includes steps such as cleaning, compiling, testing, packaging, inheriting the deployment , and maven is the abstraction of the life cycle, the specific tasks are given to the plugin to complete.


I. Maven three sets of life cycles
1 CleanLife cycle

1.1 Pre-clean work to be done before a cleanup is performed

1.2 Clean clean up the last build generated file

1.3 work to be done after a clean-up is performed


2 DefaultLife cycle

The most central part of the life cycle contains all the steps of building a project. Compile, test, package, deploy (only core content)

2.1 Source

2.2 Resource

2.3complie

2.4test

2.5test-complie

2.6 Package

2.7install

2.8 Deploy


3 SiteLife cycle

site is to build and publish the project site. This article does not focus on

Ii. Command and life cycle

execute with command line maven The task is mostly called maven life cycle phase. Each life cycle is independent of each other, and the phases of each life cycle are dependent


Command line explanation

mvn Clean: the command invokes the Clean life cycle of Clean phase. pre-clean and clean phases of the clean lifecycle in the execution phase

mvn clean Install : the command calls Cleanlife cycle of CleanStages anddefaultlife cycle ofInstallphase. The actual stage of execution is Cleanlife cycle ofPre-clean, Cleanas well

Defualt life cycle from Validate to the Install all stages of the process. combined with two life cycles.

Third, MavenPlugins

the relationship between the life cycle and the plugin. Let's start by looking at where the maven plugin is stored

maven plug-in positioning in

% Local Warehouse %\org\apache\maven\plugins, you can see some of the downloaded plugins:


For more information, check out Maven official website

   plug-in target plugin goals:

A plugin can typically accomplish multiple tasks, each of which is called a plug-in target. For the plug-in itself, multiple tasks can often be accomplished in order to reuse the code.

Such as:

maven-dependency-plugin There are more than 10 targets dependency:analyze

when we execute mvn Install command, call the plug-in and execute the following target:



Binding a plug-in to the life cycle

maven the life cycle of the plugin is bound to each other to complete the build task

This process is specific phases of the life cycle (phase) binding plug-in target ( goal) to complete. Such as: Bind the compile target of the Maven-compiler-plugin plugin to the default

The compile phase of the lifecycle completes the project's source code compilation:

such as: We compile the source code


<plugin> <!--compiled source plugin--><!--used to compile the main source code located in the src/main/java/directory--><groupid> Org.apache.maven.plugins</groupid>  <!--the only sign of the project or organization--><artifactid>maven-compiler-plugin </artifactId> <!--general name of the project--><version>${maven-compiler-plugin.version}</version><!-- Use Maven-compiler-plugin to specify JDK version and encoding--><configuration>    <!--typically used for private plugin--><source>${ Maven.compile.source}</source>        <!--compiling source code JDK version compilation--><target>${maven.compile.target}</ Target><encoding>${project.build.sourceencoding}</encoding>      <!--encoding format for file copies in Maven-- </configuration></plugin>

Summary:

Maven life cycle throughout the project, whether in the command line or in the construction of the project, can not be separated from the concept of life cycle, construction and life cycle of the relationship is one of the key

, it is important to understand the binding between the life cycle and The plugin stone through phase and goals .

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Maven Life cycle

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.