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

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

问题描述

Maven 目标和阶段之间的区别/关系是什么?它们之间的关系如何?

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

推荐答案

目标是分阶段执行的,这有助于确定目标执行的顺序.对此的最佳理解是查看 默认 Maven 生命周期绑定,显示默认情况下哪些目标在哪些阶段运行.compile 阶段目标将始终在 test 阶段目标之前执行,后者将始终在 package 阶段目标之前执行,依此类推.

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天全站免登陆