11

I am using the maven-shade-plugin to create a single executable jar. I would expect the plugin to create a single jar (foo.jar) in the target directory. However it will also create two other jars: original-foo.jar and foo-shaded.jar.

Why does it create those files and how do I disable this behavior?

(We have another project using that plugin, where those files are not created. Therefore I am pretty sure it is possible to disable those, but I could not see the difference.)

Tunaki
  • 132,869
  • 46
  • 340
  • 423
michas
  • 25,361
  • 15
  • 76
  • 121

2 Answers2

5

The plugin maven-shade-plugin by using outputFile is bypasing other behaviours:

 <plugin>

      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>

      ...

      <configuration>
           <outputFile>/tmp/watchdog.jar</outputFile>
      </configuration>

 </plugin>

More info in: https://maven.apache.org/plugins/maven-shade-plugin/shade-mojo.html#outputFile

Francisco Ferri
  • 189
  • 2
  • 11
  • An annoying problem is that you can't use `target/${project.artifactId}-${project.version}.jar`. – flow2k Apr 03 '19 at 23:22
  • maven package shows "Error creating shaded jar: error in opening zip XXX" due to the output jar is corrupt – Qoobee Jan 19 '20 at 02:51
2

You can take a look into the maven-shade-plugin documentation which will give you an the option shadedArtifactAttached which will control the behaviour your are describing.

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.3</version>
        <executions>
          <execution>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <shadedArtifactAttached>false</shadedArtifactAttached>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  ...
</project>
khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • 10
    This helped to get rid of the `foo-shaded.jar` file, but the `original-foo.jar` file is still generated. I'm also curious why the other project does not generate the `foo-shaded.jar` despite missing the above configuration. – michas May 20 '15 at 13:19
  • This didn't remove any of the jars for me. – markthegrea Apr 28 '20 at 16:35