Amongst other tasks, in development we have a need occasionally to copy static content files into our web root from a network location.
We decided to create a maven plugin to allow these tasks to be setup quickly on the command line (rather than having a collection of batch scripts to do this).
Our maven project is a multi module project with a layout similar to this:
The plugin was included in the parent pom, so that the environment setup commands could be easily excused from the parent folder.
However, the task was running multiple times. In fact, on closer inspection it was running 6 times which is exactly how many modules we have in our project.
A quick read of the Maven plugin Mojo API Specification pointed me to the javadoc annotation @requiresProject, setting this value to false (the default is true) prevents the goal being run for each module.
/** * <p> * Description of MOJO. * </p> * * @goal some-goalname * @requiresProject false * */ public class MyMojoThatDoesntRunManyTimes extends AbstractMojo ....