Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the differences between uberJar, fatJar and shadowJar in Gradle?

Tags:

I'm trying to understand when should I use which. I understand that they all assemble all the dependent classes, but how are they different from each other?

like image 626
Daniella Avatar asked Nov 18 '15 11:11

Daniella


People also ask

What is shadowJar in Gradle?

Shadow is a plugin that packages an application into an executable fat jar file if the current file is outdated. Tutorials → Working with JAR files → Fat JAR files. The task shadowJar (e.g., running the command gradlew shadowJar or gradlew clean shadowJar ) creates the JAR file in the build/libs folder.

What is Fatjar?

An uber-JAR—also known as a fat JAR or JAR with dependencies—is a JAR file that contains not only a Java program, but embeds its dependencies as well. This means that the JAR functions as an “all-in-one” distribution of the software, without needing any other Java code.

What's a shadow jar?

Shadow is a Gradle plugin for combining a project's dependency classes and resources into a single output Jar. The combined Jar is often referred to a fat-jar or uber-jar.


2 Answers

The terms are sometimes used interchangeably, but usually refers to:

  • Fat jar (also named Uber jar) - used to describe a jar that has all classes from dependent jars zipped directly inside it in the correct directory structure, and not in other jars. There is a good explanation here.

  • Shaded jar (or shaded classes) - usually refers to a process of changing classes bytecode to change packages names of the classes, and also modify were it is used in the jar. It is used to link classes to a specific version of other classes and avoid versions collisions. It can be created by Maven Shade Plugin. Shaded jar do not necessary contain all the dependencies needed.

The gradle shadow plugin can generate both fat jars and shaded jars, and same for the maven shaded plugin. I guess that is why people mix those terms.

Note: I have seen cases that refers to fat jar as a jar contains dependencies as a packed jars inside it.

like image 137
oshai Avatar answered Oct 16 '22 14:10

oshai


There is no difference whatsoever. These terms are all synonyms of each other.

The term "uber-jar" may be more commonly used in documentations (take the maven-shade-plugin documentation for example) but "fat-jar" is also widely used.

like image 36
Tunaki Avatar answered Oct 16 '22 14:10

Tunaki