tomilchik
tomilchik

Reputation: 353

Maven shade plugin is not called automatically for goal "package"

I've spent quite a bit of time figuring out how to invoke Maven shade plugin to build a uber-jar (with all dependencies). Most of the google-able info that I found (including numerous examples, and Maven documentation) suggests that all I have to do is include the plugin into pom.xml:

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

and then "mvn package" (or any other goal that eventually invokes "package") will automatically trigger this plugin.

But no matter what I tried - the only way to actually invoke the plugin appears to be: running "mvn package shade:shade" (which seems to defeat the purpose of config-driven build). Same results whether running Maven from within Eclipse (STS Version: 3.8.2.RELEASE), or from command line (Apache Maven 3.3.9).

Am I missing anything?

UPD: solved, see answer by GauravJ.

Upvotes: 25

Views: 15502

Answers (1)

GauravJ
GauravJ

Reputation: 2262

I have managed to reproduce your problem. In your pom.xml, you must have defined plugin like below,

<build>
<pluginManagement>
  <plugins>

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

  </plugins>
</pluginManagement>
</build>

instead of

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

This will probably fix your problem.

Upvotes: 47

Related Questions