The implementation of the MAVEN plugin (plugin) goal with the life cycle (lifecycle) phase relationship

Source: Internet
Author: User

Here's a good article about the Maven plugin and lifecycle:

--------------------------------------------------------------------------------------------------------------- --

This is not really a complex problem, but there seems to be no information on this clear explanation, this article will be a detailed explanation of this question.

Background Knowledge

The process of building (build) is abstracted and defined by MAVEN, a process known as the life cycle of the build (lifecycle). The Life cycle (lifecycle) consists of multiple phases (phase), each of which is hooked up to one or more goal (phase). Goal is the smallest unit in Maven that defines the task, which is equivalent to target in Ant.

build with the goal of phase

Building on phase is the most common, as we usually do MVN COMPILE,MVN TEST,MVN package ... Wait, compile,test,package are phase in the MAVEN Lifecycle (lifecycle), and with the MVN command, you can specify a build execution to that stage, during execution, all the execution phases of the experience (phase) The bound goal will be executed. For example, for a jar pack application, when the MVN package command is executed, MAVEN executes from one stage of the validate phase to the compile stage, and the compile goal of the compiler plug-in is executed, Because this goal is bound on the compile stage (phase). This can be learned from its corresponding Mojo class:

Again, for example, a frequently used packaged plug-in shade, its goal is bound to the package stage, so that the MVN package will execute shade when packaged.


build with the goal of goal

Although phase is the most common goal, sometimes we find thatsome plug-in goal are not suitable for binding to any stage (phase), or, these goal are often executed separately and do not need to be bound together at the same stage (phase), such as the import \ Export of Hibernate plug-ins goal in most cases is performed manually as needed (or, of course, can be bound to a stage, such as unit testing, consider binding it to the test phase). For example jetty (6.1.26) plug-in, its goal is to deploy packaged or unpackaged projects into the jetty and then start the jetty container, in most cases, people are running these goal independently, such as: people want to type MVN jetty:run, The project can be compiled to start jetty, and the jetty plug-in is really doing this, its run goal Mojo is declared:

where @execute phase= "Test-compile" indicates that jetty:run this goal will cause MAVEN to build to the test-compile phase before executing this goal. Similarly, for jetty: Run-war This goal requires a build to the package stage before the goal is executed.

Another example is the Exec:java of the exec plugin.

This goal also declares the phase of execute, but it is validate, so that if the code is not compiled, execution of this goal will go wrong, so in most cases people are always doing it the following way:
MVN Clean Compile Exec:java

Address: http://blog.csdn.net/bluishglc/article/details/6632280

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.