I\'ve written a plugin that generate one file in target/generated-sources/. This plugin only has one mojo. This mojo is declared with the following :
/**
*
Having your Maven plugin automatically run its default goal when its default phase executes is not possible. This is confusing because there are a lot of standard plugin ‘bindings’ for specific packagings. Those are defined in Maven core: https://maven.apache.org/ref/3.6.1/maven-core/default-bindings.html
For example, for WAR packaging it is:
<phases>
<process-resources>
org.apache.maven.plugins:maven-resources-plugin:2.6:resources
</process-resources>
<compile>
org.apache.maven.plugins:maven-compiler-plugin:3.1:compile
</compile>
<process-test-resources>
org.apache.maven.plugins:maven-resources-plugin:2.6:testResources
</process-test-resources>
<test-compile>
org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile
</test-compile>
<test>
org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test
</test>
<package>
org.apache.maven.plugins:maven-war-plugin:2.2:war
</package>
<install>
org.apache.maven.plugins:maven-install-plugin:2.4:install
</install>
<deploy>
org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy
</deploy>
</phases>
By defining a default phase in your plugin you won’t have to specify that, just the goal. In your case:
<executions>
<execution>
<id>convert</id>
<!--
Not needed for default phase of plugin goal:
<phase>generate-sources</phase>
-->
<goals>
<goal>convertsql</goal>
</goals>
</execution>
</executions>
Also see https://maven.apache.org/developers/mojo-api-specification.html (look for @phase
). The relevant quote (my emphasis):
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 element from the surrounding element.
You need to add a META-INF/plexus/components.xml
file to your plugin and set <extensions>true</extensions>
in your plugin block.
See 11.6.3. Overriding the Default Lifecycle from the Maven Book for reference