Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Update the section about "Embedding Jar Files Inside Your Shadow Jar" #1330

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions docs/configuration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,6 @@ method can be used to add extra files.

```kotlin
tasks.shadowJar {
from("extra.jar") {
// Copy extra.jar file (without unzipping) into META-INF/ in the shadowed JAR.
into("META-INF")
}
from("Foo") {
// Copy Foo file into Bar/ in the shadowed JAR.
into("Bar")
Expand All @@ -174,10 +170,6 @@ method can be used to add extra files.

```groovy
tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
from('extra.jar') {
// Copy extra.jar file (without unzipping) into META-INF/ in the shadowed JAR.
into('META-INF')
}
from('Foo') {
// Copy Foo file into Bar/ in the shadowed JAR.
into('Bar')
Expand Down
40 changes: 35 additions & 5 deletions docs/configuration/dependencies/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,41 @@ have the intended effect, as `configurations.compile` will try to delegate to th

## Embedding Jar Files Inside Your Shadow Jar

Because of the way that Gradle handles dependency configuration, from a plugin perspective, shadow is unable to
distinguish between a jar file configured as a dependency and a jar file included in the resource folder. This means
that any jar found in a resource directory will be merged into the shadow jar the same as any other dependency. If
your intention is to embed the jar inside, you must rename the jar as to not end with `.jar` before the shadow task
begins.
The `shadowJar` task is a subclass of the `Jar` task, which means that the
[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))
method can be used to add extra files.

=== "Kotlin"

```kotlin
dependencies {
// Merge foo.jar (with unzipping) into the shadowed JAR.
implementation(files("foo.jar"))
}
tasks.shadowJar {
from("bar.jar") {
// Copy bar.jar file (without unzipping) into META-INF/ in the shadowed JAR.
into("META-INF")
}
}
```

=== "Groovy"

```groovy
dependencies {
// Merge foo.jar (with unzipping) into the shadowed JAR.
implementation files('foo.jar')
}
tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
from('bar.jar') {
// Copy bar.jar file (without unzipping) into META-INF/ in the shadowed JAR.
into('META-INF')
}
}
```

See also [Adding Extra Files](../README.md#adding-extra-files)

## Filtering Dependencies

Expand Down