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 :
/**
* @goal convertsql
* @phase generate-sources
* @requiresProject
*/
public class ConverterMojo extends AbstractMojo {
In the project, i want to use the plugin but it doesn't work if i don't specify the executions tag :
<executions>
<execution>
<id>convert</id>
<goals><goal>convertsql</goal></goals>
<phase>generate-sources</phase>
</execution>
</executions>
I would like to only configure the plugin like this :
<plugin>
<groupId>com.my.plugins</groupId>
<artifactId>sqlconverter</artifactId>
<version>1.0-SNAPSHOT</version>
<configuration>
<sourceFile>src/main/resources/sql/schema_oracle.sql</sourceFile>
</configuration>
</plugin>
Is it possible to specify the default mojo for my plugin ? The default goal and phase are defined in the mojo... I mean, when using the jar plugin, i don't have to tell the goal i want to execute, at which phase... it is automatic.
Thanks!
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:
By defining a default phase in your plugin you won’t have to specify that, just the goal. In your case:
Also see https://maven.apache.org/developers/mojo-api-specification.html (look for
@phase
). The relevant quote (my emphasis):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