首页 > 编程知识 正文

理一理Maven的phase goal surefire failsafe

时间:2023-05-05 04:01:57 阅读:206691 作者:2018

理一理Maven的phase, goal, surefire, failsafe

一直在用Maven,可是今天在引用了一个插件,想要执行插件的goal的时候却完全懵了。执行mvn test的时候分不清surefire和failsafe的作用。

这可怎么行,至少要知道大概的原理才行。

首先phase是类似于Spring,Tomcat的lifecycle一样的各个阶段,这些phase是有顺序的。对Maven来说,主要的phase如下:

validate - validate the project is correct and all necessary information is availablecompile - compile the source code of the projecttest - test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployedpackage - 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 metinstall - install the package into the local repository, for use as a dependency in other projects locallydeploy - done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.

在执行phase的时候,会执行本身和它之前的phase

其次是goal。

我们现在有了生命周期,但是在每个build阶段我们具体应该做什么呢?这就是goal发挥作用了。而聪明的你肯定知道具体行为肯定是一个实现,没错,这就是为什么goal会是plugin的一个属性。当然一个plugin可以有多个goal。一个goal可以绑定到多个phase上去执行。

具体要执行某个插件的goal方法是: mvn groupId:artifactId:version:goal

最后来说一说maven-surefire-plugin和maven-failsafe-plugin插件吧。

从功能来说,一个是fail fast,一个是fail safe。从生命周期阶段上来说maven-sure-fire是test阶段的,maven-failsafe-plugin是属于integration-test阶段,这个阶段在package和verify之间,用来运行集成测试。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。