Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify a default goal for a Maven plugin?

Tags:

maven

mojo

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?

like image 501
Gili Avatar asked Jul 17 '19 15:07

Gili


People also ask

How do you specify goals in POM xml?

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.

What is Maven plugin goal?

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.

What is Maven default phase?

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.


1 Answers

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).

like image 109
J Fabian Meier Avatar answered Sep 28 '22 03:09

J Fabian Meier