7
votes

Hi I am new to Maven I am wondering how can I use a plugin without attach its goal to a particular phase. So for example I want to use shade plugin to create uber-jar(fat jar).

Goals Overview

The Shade Plugin has a single goal:

shade:shade is bound to the package phase and is used to create a shaded jar.

So the plugin has only one goal called shade.

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.3</version>
    <executions>
        <execution>
            <id>shade</id>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
        </execution>
    </executions>
</plugin>

So I said 'Hey Maven' I want to attach shade's plugin goal shade to your package lifecycle. OK but what if I remove executions configuration. What happens then can Maven understand where to put the shade goal? Does every plugin put its goals to predefined from its creator phase? And how can understand which is it this phase?

Aforementioned documentation description said the the goal is bound to package phase. Does it mean that my executions configuration is redundant?

1

1 Answers

3
votes

OK but what if I remove executions configuration What happens then can Maven understand where to put the shade goal?

If you remove the executions configuration the plugin will not run

Does every plugin put its goals to predefined from its creator phase?

Each goal can have a default phase. So even if phase is not specified and a default phase is defined, the goal will execute during that phase of the build cycle.

And how can understand which is it this phase?

This is usually specified in plugin documentation

Aforementioned documentation description said the the goal is bound to package phase. Does it mean that my executions configuration is redundant?

In your configuration phase is reduntant.

See https://maven.apache.org/guides/mini/guide-configuring-plugins.html#Using_the_executions_Tag for additional info.