0

I know I can achieve it via creating 2 modules, but just want to know is it possible to do tha it in one module ? Thanks

zjffdu
  • 25,496
  • 45
  • 109
  • 159
  • Maven Shade Plugin will _not_ suppress the creation of the "normal" JAR, so you get the desired behavior by default. – Alex Shesterov Sep 06 '18 at 09:33
  • Then how do I refer to the normal jar if you I want to use it as dependency of another project. Because I notice only the uber jar is installed in local repo – zjffdu Sep 06 '18 at 09:38
  • You can use the `outputFile` config option. Please see below. In this case, your "normal" JAR will be installed/deployed and you can define the dependency as usual. – Alex Shesterov Sep 06 '18 at 09:42

1 Answers1

2

Maven Shade Plugin, if you run the shade goal, will produce two JARs by default:

  • your-artifact.jar — the Uber-JAR, and
  • original-your-artifact.jar — the original, non-Uber-JAR.

Alternatively, you can specify a different name for the Uber-JAR by using the outputFile configuration option (see below). In this case, your "normal" JAR will have the "usual" name.

  <plugin>
    <artifactId>maven-shade-plugin</artifactId>
    <version>3.1.1</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <outputFile>${project.build.directory}/uberjar-name.jar</outputFile>
    </configuration>
  </plugin>

With this configuration, the results will be:

  • your-artifact.jar — the original, non-Uber-JAR, and
  • uberjar-name.jar — the Uber-JAR.
Alex Shesterov
  • 26,085
  • 12
  • 82
  • 103
  • could you elaborate how this works in 1/2 sentences? What does the uber jar contain, and what the other? How is this determined / controlled? Very interesting Cheers! – fl0w Sep 06 '18 at 10:40
  • 1
    @fl0w, this is perfectly explained in the following SO thread: [What is an uber jar?](https://stackoverflow.com/q/11947037/2170192) – Alex Shesterov Sep 06 '18 at 10:48
  • Thank you for the hint, I'll look into it. – fl0w Sep 06 '18 at 10:54