Skip to content

Commit 0ceb3b3

Browse files
authored
Update the section about "Embedding Jar Files Inside Your Shadow Jar" (#1330)
1 parent f1ab294 commit 0ceb3b3

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

docs/configuration/README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,6 @@ method can be used to add extra files.
159159

160160
```kotlin
161161
tasks.shadowJar {
162-
from("extra.jar") {
163-
// Copy extra.jar file (without unzipping) into META-INF/ in the shadowed JAR.
164-
into("META-INF")
165-
}
166162
from("Foo") {
167163
// Copy Foo file into Bar/ in the shadowed JAR.
168164
into("Bar")
@@ -174,10 +170,6 @@ method can be used to add extra files.
174170

175171
```groovy
176172
tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
177-
from('extra.jar') {
178-
// Copy extra.jar file (without unzipping) into META-INF/ in the shadowed JAR.
179-
into('META-INF')
180-
}
181173
from('Foo') {
182174
// Copy Foo file into Bar/ in the shadowed JAR.
183175
into('Bar')

docs/configuration/dependencies/README.md

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,41 @@ have the intended effect, as `configurations.compile` will try to delegate to th
3131

3232
## Embedding Jar Files Inside Your Shadow Jar
3333

34-
Because of the way that Gradle handles dependency configuration, from a plugin perspective, shadow is unable to
35-
distinguish between a jar file configured as a dependency and a jar file included in the resource folder. This means
36-
that any jar found in a resource directory will be merged into the shadow jar the same as any other dependency. If
37-
your intention is to embed the jar inside, you must rename the jar as to not end with `.jar` before the shadow task
38-
begins.
34+
The `shadowJar` task is a subclass of the `Jar` task, which means that the
35+
[from](https://docs.gradle.org/current/dsl/org.gradle.jvm.tasks.Jar.html#org.gradle.jvm.tasks.Jar:from(java.lang.Object,%20groovy.lang.Closure))
36+
method can be used to add extra files.
37+
38+
=== "Kotlin"
39+
40+
```kotlin
41+
dependencies {
42+
// Merge foo.jar (with unzipping) into the shadowed JAR.
43+
implementation(files("foo.jar"))
44+
}
45+
tasks.shadowJar {
46+
from("bar.jar") {
47+
// Copy bar.jar file (without unzipping) into META-INF/ in the shadowed JAR.
48+
into("META-INF")
49+
}
50+
}
51+
```
52+
53+
=== "Groovy"
54+
55+
```groovy
56+
dependencies {
57+
// Merge foo.jar (with unzipping) into the shadowed JAR.
58+
implementation files('foo.jar')
59+
}
60+
tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
61+
from('bar.jar') {
62+
// Copy bar.jar file (without unzipping) into META-INF/ in the shadowed JAR.
63+
into('META-INF')
64+
}
65+
}
66+
```
67+
68+
See also [Adding Extra Files](../README.md#adding-extra-files)
3969

4070
## Filtering Dependencies
4171

0 commit comments

Comments
 (0)