Apache Maven (ii): Build life cycle

Source: Internet
Author: User

Directory Structure of Maven conventions

I'm going to follow Maven's already agreed directory structure so that MAVEN can find the appropriate resources to build on during the automated build process. The following is the directory structure of the MAVEN contract:

Project name |--Pom.xml:Maven Project core configuration file |--src    |--main: Main program    |   | --Java:java source file    |   | --Resources: Framework or other tool profile    |--Test: Tester        |--Java:java source file        |--resources: Framework or other tool configuration file

Is that we just need to follow the directory structure to store files, Maven can automatically find the corresponding files to build processing. In addition to the following directories, there may be directories or files in the project directory that are Readme.txt,license.txt,.get,.svn,target and so on.

Maven Build life cycle

MAVEN is based on the core concepts of the build lifecycle. This means that the process of building the project has been clearly defined. For people who build projects, this means that you can build any MAVEN project by learning only a small set of commands and making sure that the Pom gets the results you want.

Maven has three built-in build lifecycles: Default,clean and site.

    • Default: Deployment of the Lifecycle Processing project (following the presenter section);
    • Clean: life cycle cleanup project;
    • Site: Life cycle processing the creation of a Web document

The default life cycle (Project deployment) consists of the following phases:

    • Validate: Verify that the project is correct and provide all the necessary information that is useful.
    • Compile: Compile the source code for the project.
    • Test: The compiled source code is tested using the appropriate unit test framework.
    • Package: Gets the compiled code and packages it into a published format, such as a jar.
    • Verify: Check the integration test results to ensure that the project complies with the quality standards.
    • Install: Installs the package to the local repository and serves as a dependency for other local projects.
    • Deploy: Complete in the build environment to replicate the final package to the remote repository for sharing with other developers and projects.

These lifecycle stages are executed sequentially to complete the default life cycle. This means that when the default life cycle is used, MAVEN validates the project, compiles the source code, runs it against the test, packages it into a binary file (such as a jar), runs the integration test package, validates the integration test, installs the validated package to the local repository, and then deploys the cursed installation software to the remote repository. Execute sequentially in sequence.

In the development environment, use the following command to build the project and install it into the local warehouse:

MVN Install

Before the install command is executed, this command executes in the order of execution of the default lifecycle stage (validate, compile, package, and so on), which can be completed by simply following the last build command of the default cycle.

In a build environment, you can use the following command to perform a cleanup build and deploy the project to a remote repository.

MVN Clean Deploy

The same command can be used in a multi-module scenario (that is, a project with one or more sub-projects). Maven iterates through each project and executes clean, then executes the deploy (including the steps before all deploy to the default life cycle).

Build projects are made up of plug-in purposes

However, while the build phase is responsible for the concrete steps of building the lifecycle, the way in which these responsibilities can be fulfilled may vary. This is done by declaring the plug-in target binding to these build phases.

The plug-in target represents a specific task (finer than the build phase) and facilitates project building and management. It can be bound to zero or more of the build phase. It is not constrained by any build phase and can be performed outside the build life cycle by direct invocation. The order of execution depends on the order of the call target and build phase, such as the following command. The clean and package of this command is the build phase, and dependency:copy-dependencies is a plug-in target.

Package

If you perform this command operation, the clean phase is performed first (meaning that the action before the clean life cycle is performed and the clean itself), and then the Dependency:copy-dependencies plug-in target is executed. Finally executes the package phase (and all previous phases of the default life cycle).

A stage that is typically named with a hyphen (pre-*,post-* or process-*) is not called directly from the command. These stages sort the build to produce intermediate results that are useless outside of the build.

Reference life cycle

The following is a list of all the build phases of the Default,clean and site life cycle. They are executed in the order given by the specified point.

  • Clean 's life cycle :
    • Pre-clean: Perform the process required before the actual project cleanup.
    • Clean: Deletes files generated from previous versions.
    • Post-clean: Perform the process required to complete the project cleanup.
  • the life cycle of default:
    • Validate: Verify that the project is correct and provide all necessary information.
    • Initialize: Initializes the build state, such as setting properties or creating a table of contents.
    • Generate-sources: Generates any source code that is included in the compilation.
    • Process-sources: Handles source code, such as filtering some values.
    • Generate-resources: Generates the resources contained in the package.
    • Process-resources: The resource is copied and processed into the target directory, ready to be packaged.
    • Compile: Compile the source code for the project.
    • Process-classes: Processes files generated from a compilation, such as bytecode enhancement on Java classes.
    • Generate-test-sources: Generates some test source code that is included in the compilation.
    • Process-test-sources: Process The test source code, such as filtering some values.
    • Generate-test-resources: Create a test resource file.
    • Process-test-resources: The resource is copied and processed into the test target directory.
    • Test-compile: Compile the test source code into the test target directory.
    • Process-test-classes: Processing generated files from test compilation, such as byte-code enhancement on Java classes
    • Test: Run the tests using the appropriate unit test framework. These tests should not require packaging or deploying code.
    • Prepare-package: Perform some necessary pre-packaged operations before actually packaging. This usually causes the package to be decompressed.
    • Package: Accepts compiled code and packages it into a published format, such as a jar.
    • Pre-integration-test: Perform the required action before the integration test executes. This may involve things such as setting the desired environment.
    • Integration-test: If required, packages can be processed and deployed to an environment where integration testing can run.
    • Post-integration-test: Perform the required actions after the integration test. This may include cleaning up the environment.
    • Verify: Run some checks to verify that the package is valid and complies with the quality standards.
    • Install: Installs the package to the local repository as a dependency on other local projects.
    • Deploy: Complete in an integration or release environment, copying the final package to a remote repository for sharing with other developers and projects.
  • Life cycle of site :
    • Pre-site: Perform the process required before the actual project site is built.
    • Site: Build the project's website document.
    • Post-site: Perform the process required to complete the site build and prepare for site deployment.
    • Site-deploy: Deploys the generated Web site document to the specified Web server.

Apache Maven (ii): Build 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.