Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

plugins

maven

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.

like image 689
tomilchik Avatar asked Feb 13 '17 16:02

tomilchik


People also ask

How does maven shade plugin work?

This plugin provides the capability to package the artifact in an uber-jar, including its dependencies and to shade - i.e. rename - the packages of some of the dependencies.

How do you shade a dependency?

In Java, to “shade” a dependency is to include all its classes and the classes from its transitive dependencies in your project, often renaming the packages and rewriting all affected bytecode.


1 Answers

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.

like image 114
GauravJ Avatar answered Sep 16 '22 12:09

GauravJ