Getting Started¶
plugins {
java
id("com.gradleup.shadow") version "<version>"
}
plugins {
id 'java'
id 'com.gradleup.shadow' version '<version>'
}
Alternatively, the plugin can be added to the buildscript classpath and applied:
buildscript {
repositories {
mavenCentral()
gradlePluginPortal()
}
dependencies {
classpath("com.gradleup.shadow:shadow-gradle-plugin:<version>")
}
}
// `apply plugin` stuffs are used with `buildscript`.
apply(plugin = "java")
apply(plugin = "com.gradleup.shadow")
buildscript {
repositories {
mavenCentral()
gradlePluginPortal()
}
dependencies {
classpath 'com.gradleup.shadow:shadow-gradle-plugin:<version>'
}
}
// `apply plugin` stuffs are used with `buildscript`.
apply plugin: 'java'
apply plugin: 'com.gradleup.shadow'
Snapshots of the development version are available in
Sonatype’s snapshots repository.
buildscript {
repositories {
mavenCentral()
maven("https://oss.sonatype.org/content/repositories/snapshots/")
}
dependencies {
classpath("com.gradleup.shadow:shadow-gradle-plugin:<version>")
}
}
// `apply plugin` stuffs are used with `buildscript`.
apply(plugin = "java")
apply(plugin = "com.gradleup.shadow")
Snapshots of the development version are available in
Sonatype’s snapshots repository.
buildscript {
repositories {
mavenCentral()
maven { url = 'https://oss.sonatype.org/content/repositories/snapshots/' }
}
dependencies {
classpath 'com.gradleup.shadow:shadow-gradle-plugin:<version>'
}
}
// `apply plugin` stuffs are used with `buildscript`.
apply plugin: 'java'
apply plugin: 'com.gradleup.shadow'
NOTE: The correct maven coordinates for each version of Shadow can be found by referencing the Gradle Plugin documentation here.
Shadow is a reactive plugin.
This means that applying Shadow by itself will perform no configuration on your project.
Instead, Shadow reacts
This means, that for most users, the java
or groovy
plugins must be explicitly applied
to have the desired effect.
Default Java/Kotlin/Groovy Tasks¶
In the presence of the java
, org.jetbrains.kotlin.jvm
or groovy
plugins (that apply JavaPlugin
in their build logic), Shadow will automatically configure the following behavior:
- Adds a
ShadowJar
task to the project. - Adds a
shadow
configuration to the project. - Adds a
shadow
variant to the project. - Adds a
shadow
component to the project. - Configures the
ShadowJar
task to include all sources from the project’smain
sourceSet. - Configures the
ShadowJar
task to bundle all dependencies from theruntimeClasspath
configuration. - Configures the classifier attribute of the
ShadowJar
task to be'all'
. - Configures the
ShadowJar
task to generate aManifest
with:- Inheriting all configuration from the standard
Jar
task. - Adds a
Class-Path
attribute to theManifest
that appends all dependencies from theshadow
configuration
- Inheriting all configuration from the standard
- Configures the
ShadowJar
task to exclude any JAR index or cryptographic signature files matching the following patterns:META-INF/INDEX.LIST
META-INF/*.SF
META-INF/*.DSA
META-INF/*.RSA
META-INF/versions/**/module-info.class
module-info.class
- Creates and registers the
shadow
component in the project (used for integrating withmaven-publish
).
ShadowJar Command Line options¶
Sometimes, a user wants to declare the value of an exposed task property on the command line instead of the
build script. Passing property values on the command line is particularly helpful if they change more frequently.
Here are the options that can be passed to the shadowJar
:
--enable-relocation Enable relocation of packages in the jar
--no-enable-relocation Disables option --enable-relocation
--minimize-jar Minimize the jar by removing unused classes
--no-minimize-jar Disables option --minimize-jar
--relocation-prefix Prefix to use for relocated packages
--rerun Causes the task to be re-run even if up-to-date
Also, you can view more information about the ShadowJar
task by running the following command:
./gradlew -q help --task shadowJar
Refer to listing command line options.