A JAR is a package file format typically used to aggregate many Java class files and associated metadata and resources into one file for distribution. It is used to store classes of java created by the user in order to help the runnable and inference concepts embedded within the language.

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.

In this section, we will be creating a fat JAR (one that contains all test classes too, as our project sits within ‘test’), which we can then easily use and distribute (e.g. on build servers).

To do this, we will be using the handy Gradle plugin Shadow.

Adding Shadow Plugin

  1. Open up the build.gradle file and add the following plugins underneath the ‘apply plugin: java’ line…

  2. Add ‘jCenter()’ underneath ‘mavenCentral()’ in the repositiories list/section…
  3. Also add the following build scripts ‘repositories’ section to look like below, as we need to add a new repository source ‘jcenter’ as well as the classpath for the Shadow plugin…

    If you get an error about Shadow plugin only being supported with Gradle v5.0+, then simply update the version in your file (located at <projectRoot>/gradle/wrapper directory)…
  4. In its current form, the whole build.gradle file should look like below…

Adding shadowJar Gradle Task

Let’s now add a Gradle task that when run, will create the fat JAR for us 🙂

  1. In the build.gradle file, add the following task, changing ‘whateverYouWant’ to a name appropriate for your project…

    The whole thing should look like below…

We can now build our JAR file by opening a Terminal window and entering the command: ./gradlew shadowJaR

The JAR file will be built by default into <projectRoot>/build/libs directory

In the next section, we will move towards scaling up our parallel test execution with a Selenium Grid inside docker containers 😀

Liked it? Take a second to support Thomas on Patreon!

Previous Article

Next Article

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.