Maven: Bind plugin execution to the execution of another plugin, not to a lifecycle phase

房东的猫 提交于 2019-12-03 01:23:45

No, you can't bind to a plugin to another plugin. Only to a phase.

In Maven-internal terms, a "Mojo" is the thing that does work. A "plugin" is a collection of mojos wrapped up so you can reference them from the POM. Mojos bind to phases only.

From the plugin development documentation:

Each Mojo specified inside a plugin descriptor must provide the following

...

phase ... Defines a default phase to bind a mojo execution to if the user does not explicitly set a phase in the POM. Note: This annotation will not automagically make a mojo run when the plugin declaration is added to the POM. It merely enables the user to omit the <phase> element from the surrounding <execution> element.

For further confirmation, see the source of MojoExecution (the JavaDoc for this class isn't helpful) and notice that there are two possible sources of execution enumerated:

An execution that originates from the direct invocation of a goal from the CLI

and

An execution that originates from a goal bound to a lifecycle phase

No other way to kick off an execution means you're out of luck (barring extraordinary measures like rolling your own plugin that combines the effects of the two plugins you want to link and then using your custom plugin).

Mihai Danila

The evidence presented so far is rather circumstantial. I've done some research of my own, so it's best I share it here. The below are either more of the same "it's not possible", or the building blocks for alternatives.

jetspeed:mvn plugin --- run a specified sequence of plugins; the configuration to run can be varied via a system property; IDE integration concerns


Executing goals before plugin runs (StackOverflow) --- same question answered in the context of a custom Mojo


Make Mojo run other goals (StackOverflow) --- again, from the context of a custom Mojo


Configuring default Mojo executions --- Maven page describing how Mojos run - more circumstantial evidence


Triggering phases before goal execution (StackOverflow) --- roundabout solution to my problem, unfortunately answered in the negative


INTERESTING: Guide to Ant plugin development --- appealing to me, because, while it requires writing a custom plugin, it's all Ant + Maven configuration, no code to compile; presumably a lower barrier to entry


Creating a parallel lifecycle --- appealing approach, because I could fully control the contents of the lifecycle to where it would use Gitflow verbs; unclear how IDEs would integrate this; learning curve and adoption barrier concerns exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!