blah blah blah
Shadow is an extension of the Gradle Jar task that optimizes FatJar/UberJar creation by using JarInputStream and JarOutputStream to copy file contents. This avoids the unnecessary I/O overhead of expanding jar files to disk before recombining them. Shadow provides the similar filtering, relocation, and transformation capabilities as the Maven Shade plugin. Starting with version 0.9, Shadow is a complete re-write based on core Gradle classes and concepts instead of a port of the Maven Shade code. Documentation for version 0.8 and prior can be found here
buildscript {
repositories { jcenter() }
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:0.9.0-M3'
}
}
apply plugin: 'com.github.johnrengelman.shadow'
$ gradle shadowJar //shadow the runtime configuration with project code into ./build/libs/
shadowJar
by uses the same default configurations as jar
and additionally configures the classifier
to be "all"
.
Additionally, it creates a 'shadow' configuration and assigns the jar as an artifact of it. This configuration can
be used to add dependencies that are excluded from the shadowing.
By default, uses the same manifest as the Jar
task.
jar {
manifest {
attributes("Implementation-Title": "Gradle", "Implementation-Version": version)
}
}
Append to the Jar MANIFEST
shadowJar {
appendManifest {
attributes 'Test-Entry': 'PASSED'
}
}
Replace the Jar MANIFEST
shadowJar {
manifest {
attributes("Implementation-Title": "Gradle", "Implementation-Version": version)
}
}
shadowJar {
mergeServiceFiles()
}
OR
import com.github.jengelman.gradle.plugins.shadow.transformers.ServiceFileTransformer
shadowJar {
transform(ServiceFileTransformer)
}
shadowJar {
append('NOTICE')
}
OR
import com.github.jengelman.gradle.plugins.shadow.transformers.AppendingTransformer
shadowJar {
transform(AppendingTransformer) {
resource = 'NOTICE'
}
}
shadowJar {
exclude 'LICENSE'
}
Remove an external dependency and all of its transitive dependencies
shadowJar {
exclude(dependency('asm:asm:3.3.1'))
}
Remove an external dependency but keep its transitive dependencies
shadowJar {
exclude(dependency('asm:asm:3.3.1'), false)
}
Exclude a project dependency in a multi-project build
shadowJar {
exclude(project(":myclient"))
}
Exclude a dependency and its transitives, except specified subset
Not currently supported
shadowJar {
relocate 'org.objectweb.asm', 'myjarjarasm.asm'
}
shadowJar {
relocate('org.objectweb.asm', 'myjarjarasm.asm') {
exclude 'org.objectweb.asm.ClassReader'
}
}
Uses the Transformer interface.
shadowJar {
transform(<Transformer class>) {
//..configure the Transformer class instance
}
}
TODO - need to implement this
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'maven-publish'
publishing {
publications {
shadow(MavenPublication) {
from components.java
artifact shadowJar
}
}
}
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'maven-publish'
shadowJar {
baseName = 'myproject-all'
classifier = ''
}
publishing {
publications {
shadow(MavenPublication) {
from components.shadow
artifactId = 'myproject-all'
}
}
}
dependencies {
compile 'asm:asm:3.3.1'
compile 'org.bouncycastle:bcprov-jdk15on:1.47'
shadow 'org.bouncycastle:bcprov-jdk15on:1.47'
}
shadowJar {
exclude(dependency('org.bouncycastle:bcprov-jdk15on:1.47'))
}
This examples allows the project to compile against the BouncyCastle encryption library, but then excludes it from the shadowed jar, but including it as a dependency on the 'shadow' configuration.