Maven plugin development: is there a way to automatically run the plugin when it is just declared in pom.xml?

I am developing a new mojo. It has only one purpose, so it’s logical not to force the user to add the executions section (unless they want to change the default value of phase ).

This should be possible because when I add a very simple description of the surefire plugin, maven realizes that its only test target should be running, surefire .:

  <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.4.3</version> </plugin> 

and this is enough to run the plugin.

How can I achieve the same small configuration for my plugin?

Here is what I have (and it does not work without the executions section):

 /** * * @goal test * @phase test */ public class MyMojoPlugin extends AbstractMojo { ... (implementation details) } 

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.somegroup</groupId> <artifactId>mymojo-maven-plugin</artifactId> <packaging>maven-plugin</packaging> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-plugin-api</artifactId> <version>2.0</version> </dependency> .... (other dependencies) </dependencies> <build> <plugins> ... (some plugins) </plugins> </build> </project> 
+4
source share
1 answer

The default lifecycle binding is defined in Maven. This is described in the Build Lifecycle document, which also indicates that plugins require a "run" section.

I suggest that you could edit components.xml and recompile Maven for your specific site.

In my opinion, the best alternative, at least for internal development, is to use a common parent POM, which contains a site-specific configuration.

Edit: I was looking for a link to the parent POM and saw this . I'm not sure if this is a Maven3 feature, but it is probably worth exploring it.

+2
source

All Articles