Note: this thread is about writing a custom Mojo, not using a plugin.
I maintain a testing plugin for Maven. Unfortunately, for almost a year now, I've let this particular unknown linger and I'd really like to know how to deal with it so that its users can have a simpler configuration.
Let's say we have two goals in our plugin:
prepare
(phase: generate-sources)do
(phase: compile)
I want to configure the do
Mojo to require prepare
to have been executed in the earlier phase of the build. However, nothing in the descriptor documentation suggests开发者_StackOverflow社区 I can.
The user probably doesn't care or understand the point of the prepare
goal, so I don't want to force them to specify it in their POM. Of course, I could execute the Mojo directly from do
, but then the prepare
goal will have run at a later phase than is intended.
(I looked into custom lifecycles, but that makes it appear that everyone who already has the prepare
goal in their POMs will have it executed twice upon running do
.)
You could have something like the below (taken from the CompilerMojo):
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id: CompilerMojo.java 941498 2010-05-05 21:24:11Z krosenvold $
* @since 2.0
* @goal compile
* @phase compile
* @threadSafe
* @requiresDependencyResolution compile
*/
By setting this over your class, it will execute during the compile phase (in this example). The compile phase requires all the previous phases to have executed first (validate, generate-sources, process-sources, generate-resources, process-resources
...).
Basically, pick a phase after the one you need (or even the same one) and it should work.
精彩评论