I've defined a Maven plugin with multiple goals. Currently users run my plugin as follows:
<plugin>
<groupId>myGroupId</groupId>
<artifactId>myArtifactId</artifactId>
<version>someVersion</version>
<executions>
<execution>
<goals>
<goal>myGoal</goal>
</goals>
</execution>
</executions>
</plugin>
but I've seen other plugins, like maven-compiler-plugin
and Flyway, that don't require specifying an execution
: https://flywaydb.org/getstarted/java
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>5.2.4</version>
<configuration>
<url>jdbc:h2:file:./target/foobar</url>
<user>sa</user>
<locations>
<location>classpath:db/migration</location>
</locations>
</configuration>
</plugin>
How do I specify the goal that should run by default when users exclude the <executions>
block?
We can also configure goals in the pom. xml file using the plugins element. This is mostly required when you have created a custom plugin and want to execute any specific goal for a build phase.
Plugin is a collection of goals also called MOJO (Maven Old Java Object). Analogy : Plugin is a class and goals are methods within the class. Maven is based around the central concept of a Build Life Cycles. Inside each Build Life Cycles there are Build Phases, and inside each Build Phases there are Build Goals.
The Maven build follows a specific lifecycle to deploy and distribute the target project. There are three built-in lifecycles: default: the main lifecycle, as it's responsible for project deployment. clean: to clean the project and remove all files generated by the previous build.
AFAIK, there are not default goals for Maven plugins.
You can configure a plugin without adding a goal. But this does not execute the plugin.
The plugin must be either executed explicitly on command line (like flyway:migrate
) or is executed automatically through the lifecycle (like compile:compile
or jar:jar
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With