21

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.

tomilchik
  • 313
  • 1
  • 2
  • 6
  • 1
    Please show your full pom file...I assume you have it in the wrong location.. – khmarbaise Feb 13 '17 at 16:32
  • I'd be happy to - but pom.xml is rather large to include in its entirety here. Can you elaborate on how you think the contents of pom.xml may be related to its being in the wrong location? The location looks to be pretty standard (Eclipse placed it into the usual place, under the project root). – tomilchik Feb 13 '17 at 17:24

1 Answers1

40

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.

Binita Bharati
  • 5,239
  • 1
  • 43
  • 24
GauravJ
  • 2,162
  • 1
  • 22
  • 28