Maven的目标和阶段是什么,它们之间有什么区别? [英] What are Maven goals and phases and what is their difference?

查看:167
本文介绍了Maven的目标和阶段是什么,它们之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Maven目标和阶段之间有什么区别/关系?它们如何相互关联?

What is the difference/relation between Maven goals and phases? How they are related to each other?

推荐答案

目标是分阶段执行的,有助于确定要执行的订单目标.对此的最佳理解是查看

Goals are executed in phases which help determine the order goals get executed in. The best understanding of this is to look at the default Maven lifecycle bindings which shows which goals get run in which phases by default. The compile phase goals will always be executed before the test phase goals which will always be executed before the package phase goals and so on.

当您执行Maven时可以指定目标或阶段,这一事实加剧了部分困惑.如果您指定一个阶段,则maven将按顺序运行所有阶段,直到您指定的阶段(例如,如果您指定软件包,它将首先运行编译阶段,然后是测试阶段,最后是软件包阶段),并且对于每个阶段,达到该阶段的所有目标.

Part of the confusion is exacerbated by the fact that when you execute maven you can specify a goal or a phase. If you specify a phase then maven will run all phases up to the phase you specified in order (e.g. if you specify package it will first run through the compile phase and then the test phase and finally the package phase) and for each phase it will run all goals attached to that phase.

当您在Maven构建文件中创建插件执行时,仅指定目标时,它将将该目标绑定到给定的默认阶段.例如,默认情况下,jaxb:xjc目标绑定到generate-resources阶段.但是,当您指定执行方式时,您也可以显式指定该目标的阶段.

When you create a plugin execution in your Maven build file and you only specify the goal then it will bind that goal to a given default phase. For example, the jaxb:xjc goal binds by default to the generate-resources phase. However, when you specify the execution you can also explicitly specify the phase for that goal as well.

如果在执行Maven时指定目标,则它将运行该目标,并且仅运行该目标.换句话说,如果您指定jar:jar目标,它将仅运行jar:jar目标以将您的代码打包到jar中.如果您以前没有运行过编译目标或以其他方式准备了已编译的代码,则很可能会失败.

If you specify a goal when you execute Maven then it will run that goal and only that goal. In other words, if you specify the jar:jar goal it will only run the jar:jar goal to package your code into a jar. If you have not previously run the compile goal or prepared your compiled code in some other way this may very likely fail.

这篇关于Maven的目标和阶段是什么,它们之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆