|
1 | 1 | <div style="text-align: center;">
|
2 |
| - <img src="images/logo.svg" alt="Shadow Gradle Plugin" style="max-width: 300px; height: auto;"> |
| 2 | + <img src="images/logo.svg" alt="Shadow Gradle Plugin" width="300"/> |
3 | 3 | <h1><strong>Shadow Gradle Plugin</strong></h1>
|
4 |
| - <p><em>The library author's dependency toolkit</em></p> |
5 | 4 | </div>
|
6 | 5 |
|
7 |
| ---- |
| 6 | +# Introduction |
8 | 7 |
|
9 |
| -Previously this plugin was developed by [@johnrengelman](https://github.com/johnrengelman) and published under the ID [ |
10 |
| -`com.github.johnrengelman.shadow`](https://plugins.gradle.org/plugin/com.github.johnrengelman.shadow) |
11 |
| -before maintenance was transferred to the [GradleUp organization](https://github.com/GradleUp) to ensure future |
12 |
| -development, see [#908](https://github.com/GradleUp/shadow/issues/908). |
| 8 | +Shadow is a Gradle plugin for combining a project's dependency classes and resources into a single |
| 9 | +output Jar. |
| 10 | +The combined Jar is often referred to a _fat-jar_ or _uber-jar_. |
| 11 | +Shadow utilizes [`JarInputStream`](https://docs.oracle.com/javase/8/docs/api/java/util/jar/JarInputStream.html) and [`JarOutputStream`](https://docs.oracle.com/javase/8/docs/api/java/util/jar/JarOutputStream.html) to efficiently process dependent libraries |
| 12 | +into the output jar without incurring the I/O overhead of expanding the jars to disk. |
13 | 13 |
|
14 |
| -If you are still using the old plugin ID in your build script, we recommend to switch to the new plugin ID [ |
15 |
| -`com.gradleup.shadow`](https://plugins.gradle.org/plugin/com.gradleup.shadow) |
16 |
| -and update to the latest version to receive all the latest bug fixes and improvements. |
| 14 | +!!! warning "Plugin ID Change" |
| 15 | + |
| 16 | + Previously this plugin was developed by [@johnrengelman](https://github.com/johnrengelman) and published under the ID [ |
| 17 | + `com.github.johnrengelman.shadow`](https://plugins.gradle.org/plugin/com.github.johnrengelman.shadow) |
| 18 | + before maintenance was transferred to the [GradleUp organization](https://github.com/GradleUp) to ensure future |
| 19 | + development, see [#908](https://github.com/GradleUp/shadow/issues/908). |
| 20 | + |
| 21 | + If you are still using the old plugin ID in your build script, we recommend to switch to the new plugin ID [ |
| 22 | + `com.gradleup.shadow`](https://plugins.gradle.org/plugin/com.gradleup.shadow) |
| 23 | + and update to the latest version to receive all the latest bug fixes and improvements. |
| 24 | + |
| 25 | +## Benefits of Shadow |
| 26 | + |
| 27 | +Shadowing a project output has 2 major use cases: |
| 28 | + |
| 29 | +1. Creating an _executable_ JAR distribution |
| 30 | +2. Bundling and relocating common dependencies in libraries to avoid classpath conflicts |
| 31 | + |
| 32 | +### Executable Distributions |
| 33 | + |
| 34 | +Executable distribution is the main use case for deploying an _application_ that can be executed/run in the runtime |
| 35 | +environment. |
| 36 | +In the case of Shadow, this is a single _uber_ or _fat_ JAR. |
| 37 | +The JAR file contains all the application code and dependent libraries to execute (not including the standard JVM |
| 38 | +libraries). |
| 39 | +The shadow JAR does **not** include the JRE itself. |
| 40 | +It must be available on the target system. |
| 41 | + |
| 42 | +Executable JARs contain a JAR MANIFEST that specifies the application Main Class. |
| 43 | +This allows the application to be started with a single command: |
| 44 | + |
| 45 | +```shell |
| 46 | +java -jar application-shadow.jar |
| 47 | +``` |
| 48 | + |
| 49 | +### Library Bundling |
| 50 | + |
| 51 | +Dependency bundling and relocation is the main use case for _library_ authors. |
| 52 | +The goal of a bundled library is to create a pre-packaged dependency for other libraries or applications to utilize. |
| 53 | +Often in these scenarios, a library may contain a dependency that a downstream library or application also uses. |
| 54 | +In _some_ cases, different versions of this common dependency can cause an issue in either the upstream library or |
| 55 | +the downstream application. |
| 56 | +These issues often manifest themselves as binary incompatibilities in either the library or application code. |
| 57 | + |
| 58 | +By utilizing Shadow's ability to _relocate_ the package names for dependencies, a library author can ensure that the |
| 59 | +library's dependencies will not conflict with the same dependency being declared by the downstream application. |
0 commit comments