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` stuff 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` stuff are used with `buildscript`.
apply plugin: 'java'
apply plugin: 'com.gradleup.shadow'
Snapshots of the development version are available in Central Portal Snapshots.
buildscript {
repositories {
mavenCentral()
maven("https://central.sonatype.com/repository/maven-snapshots/")
}
dependencies {
// You can get the latest snapshot version from `VERSION_NAME` declared in https://github.com/GradleUp/shadow/blob/main/gradle.properties
classpath("com.gradleup.shadow:shadow-gradle-plugin:<version>")
}
}
// `apply plugin` stuff are used with `buildscript`.
apply(plugin = "java")
apply(plugin = "com.gradleup.shadow")
Snapshots of the development version are available in Central Portal Snapshots.
buildscript {
repositories {
mavenCentral()
maven { url = 'https://central.sonatype.com/repository/maven-snapshots/' }
}
dependencies {
// You can get the latest snapshot version from `VERSION_NAME` declared in https://github.com/GradleUp/shadow/blob/main/gradle.properties
classpath 'com.gradleup.shadow:shadow-gradle-plugin:<version>'
}
}
// `apply plugin` stuff 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
ShadowJartask to the project. - Adds a
shadowconfiguration to the project. - Adds a
shadowvariant to the project. - Adds a
shadowcomponent to the project. - Configures the
ShadowJartask to include all sources from the project’smainsourceSet. - Configures the
ShadowJartask to bundle all dependencies from theruntimeClasspathconfiguration. - Configures the classifier attribute of the
ShadowJartask to be'all'. - Configures the
ShadowJartask to generate aManifestwith:- Inheriting all configuration from the standard
Jartask. - Adds a
Class-Pathattribute to theManifestthat appends all dependencies from theshadowconfiguration
- Inheriting all configuration from the standard
- Configures the
ShadowJartask to exclude any JAR index or cryptographic signature files matching the following patterns:META-INF/INDEX.LISTMETA-INF/*.SFMETA-INF/*.DSAMETA-INF/*.RSAMETA-INF/versions/**/module-info.classmodule-info.class
- Creates and registers the
shadowcomponent 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:
--add-multi-release-attribute Adds the multi-release attribute to the manifest if any dependencies contain it.
--no-add-multi-release-attribute Disables option --add-multi-release-attribute.
--enable-auto-relocation Enables auto relocation of packages in the dependencies.
--no-enable-auto-relocation Disables option --enable-auto-relocation.
--fail-on-duplicate-entries Fails build if the ZIP entries in the shadowed JAR are duplicate.
--no-fail-on-duplicate-entries Disables option --fail-on-duplicate-entries.
--main-class Main class attribute to add to manifest.
--minimize-jar Minimizes the jar by removing unused classes.
--no-minimize-jar Disables option --minimize-jar.
--relocation-prefix Prefix used for auto relocation of packages in the dependencies.
--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.