Maven生命周期解释

http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

Build Lifecycle Basics

Maven is based around the central concept of a build lifecycle. What this means is that the process for building and distributing a particular artifact (project) is clearly defined.

For the person building a project, this means that it is only necessary to learn a small set of commands to build any Maven project, and the POM will ensure they get the results they desired.

There are three built-in build lifecycles: default, clean and site. The default lifecycle handles your project deployment, the clean lifecycle handles project cleaning, while the site lifecycle handles the creation of your project's site documentation.

A Build Lifecycle is Made Up of Phases

Each of these build lifecycles is defined by a different list of build phases, wherein a build phase represents a stage in the lifecycle.

For example, the default lifecycle comprises of the following phases (for a complete list of the lifecycle phases, refer to the Lifecycle Reference):

  • validate - validate the project is correct and all necessary information is available
  • compile - compile the source code of the project
  • test - test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
  • package - take the compiled code and package it in its distributable format, such as a JAR.
  • verify - run any checks on results of integration tests to ensure quality criteria are met
  • install - install the package into the local repository, for use as a dependency in other projects locally
  • deploy - done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.

These lifecycle phases (plus the other lifecycle phases not shown here) are executed sequentially to complete the default lifecycle. Given the lifecycle phases above, this means that when the default lifecycle is used, Maven will first validate the project, then will try to compile the sources, run those against the tests, package the binaries (e.g. jar), run integration tests against that package, verify the integration tests, install the verified package to the local repository, then deploy the installed package to a remote repository.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Maven生命周期定义了一系列的阶段(phases),每个阶段包含了一组插件目标(goals)。在Maven构建过程中,一般会按照生命周期的顺序执行这些阶段和目标。 Maven生命周期分为三个主要的生命周期: 1. Clean生命周期:该生命周期与项目的清理相关,用于清除先前构建生成的文件。 - clean:清理项目,删除生成的目录和文件。 2. Default生命周期:该生命周期是项目构建的核心,负责编译、测试、打包、部署等操作。 - validate:验证项目是否正确且所有必要信息都可用。 - compile:编译项目的源代码。 - test:使用合适的单元测试框架运行测试。 - package:将编译后的代码打包成可发布的格式,如JAR、WAR。 - verify:对集成测试的结果进行检查,以保证质量达标。 - install:将包安装到本地仓库,供其他项目使用。 - deploy:将最终的包复制到远程仓库,供其他开发人员和项目使用。 3. Site生命周期:该生命周期用于生成项目的站点文档。 - site:生成项目站点的文档。 - site-deploy:将生成的站点发布到服务器上。 需要注意的是,Maven生命周期中的每个阶段和目标都有其预定的执行顺序,且每个阶段都会执行其前面的所有阶段。你可以通过在命令行中执行`mvn <phase>`来运行指定的生命周期阶段。 需要注意的是,Maven生命周期是可扩展的,可以通过自定义插件来添加额外的阶段和目标。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值