Maven Learning Notes (i)

Source: Internet
Author: User

In the company project to use MAVEN, specifically, in fact, only use a few of Maven's simple commands, mvn clean,mvn package,mvn Install, mvn deploy. I haven't spent much time to see what this is really like (or lazy).

Maven, in a nutshell, is a Java Project Building tool, and the most common feature might be to address the pain of the dependency of each project on the jar package. Because language is the cause of Java, so a project will often introduce a lot of open-source jar, each jar has a version and so on, so think is also drunk. And then because I personally do Java development is not very long, so no ant (this is also a project build tool, born earlier than Maven), and now the latest build tool may be gradle bar, the previous time in the spring framework of the source code, https:// Github.com/spring-projects/spring-framework is already using this build tool.

  

We visit MAVEN's official website https://maven.apache.org/under index (catagory) under documentation to view some of the documents. Introductions explains some of the core concepts that are common in maven.

Here I focus on build lifecycle, the life cycle of the MAVEN build project.

There are three built-in build declaration cycles: Default,clean and site.

The default declaration cycle deals with project deployment, clean processing of project cleanup, site processing of project document creation.

    Build lifecycle is made up of phases, a few important phase in the default build lifecycle  

Validate verify that the project is correct and that the necessary information is available compile compile the source code test after the compiled code, that is, execute the unit test code package after the compiled code, Build the package file under the target directory integration-test process the assembly so that it can be deployed to the integration test environment when needed verify verify that the package is valid and meets the quality standard install the product to the local warehouse , facilitate local other projects using deploy deployment, copy the final package to the remote repository and develop this or project share for him, complete in the integration or release environment

    The above phase is ordered (note that the actual two adjacent phase between the other phase is omitted, the complete phase see Lifecycle), the following phase must be performed after the last phase if directly to a phase for goal, The phase, such as mvn install, will first be executed before it validate, compile, test, package, Integration-test, Verify finally executes the install phase.

  

    About the core concepts of maven and so on you can read this blog http://www.trinea.cn/android/maven/The explanation of goal I don't agree with, you can look at Maven's official explanation:

A Build Phase is made up of Plugin goals

However, even though a build phase is responsible for a specific step in the build lifecycle, the manner in which it Carri Es out those responsibilities may vary. And this is do by declaring the plugin goals bound to those build phases.

A plugin goal represents a specific task (finer than a build phase) which contributes to the building and managing of a PR Oject. It is bound to zero or more build phases. A goal not bound to any build phase could is executed outside of the build lifecycle by direct invocation. The order of execution depends on the order in which the goal (s) and the build phase (s) is invoked. For example, consider the command below. The Cleanand PackageArguments is build phases, while thedependency:copy-dependenciesis a goal (of a plugin).

MVN Clean Dependency:copy-dependencies Package

If this were to is executed, the CleanPhase'll be executed first (meaning it'll run all preceeding phases of the "clean lifecycle, plus the CleanPhase itself), and then thedependency:copy-dependenciesGoal, before finally executing the PackagePhase (and all its preceeding build phases of the default lifecycle).

Moreover, if a goal is bound to one or more build phases, that goal would be called in all those phases.

Furthermore, a build phase can also has zero or more goals bound to it. If a build phase have no goals bound to it, that build phase would not execute. But if it had one or more goals bound to it, it would execute all those goals

(note:in Maven 2.0.5 and above, multiple goals bound to a phase is executed in the same order as they is declared I n the POM, however multiple instances of the same plugin is not supported. Multiple instances of the same plugin is grouped to execute together and ordered in Maven 2.0.11 and above).

I think the maven command is based on plugins, and goal is a brief description of the functionality implemented by the Pilugin, phase is bound together with plugin goal to execute mvn-phase.

Maven Learning Notes (i)

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.