From 72d7a99952539559f2e0972ba784a7a8c378417b Mon Sep 17 00:00:00 2001 From: Goooler Date: Fri, 8 Aug 2025 10:58:01 +0800 Subject: [PATCH 1/7] Call `from(archiveOperations.zipTree(file))` --- .../gradle/plugins/shadow/tasks/ShadowJar.kt | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt index 386a08e9f..44a52b240 100644 --- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt +++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt @@ -345,19 +345,18 @@ public abstract class ShadowJar : Jar() { @TaskAction override fun copy() { - from( - includedDependencies.files.map { file -> - if (file.extension.equals("aar", ignoreCase = true)) { - val message = """ + includedDependencies.files.map { file -> + if (file.extension.equals("aar", ignoreCase = true)) { + val message = """ Shadowing AAR file is not supported. Please exclude dependency artifact: $file or use Android Fused Library plugin instead. See https://developer.android.com/build/publish-library/fused-library. - """.trimIndent() - error(message) - } - archiveOperations.zipTree(file) - }, - ) + """.trimIndent() + error(message) + } + + from(archiveOperations.zipTree(file)) + } injectMultiReleaseAttrIfPresent() super.copy() } From fc88b151d49e9a02ab622b894f6cc29b3917061e Mon Sep 17 00:00:00 2001 From: Goooler Date: Fri, 8 Aug 2025 11:02:45 +0800 Subject: [PATCH 2/7] Check AAR files are regular files --- .../github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt index 44a52b240..41a7173cd 100644 --- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt +++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt @@ -346,7 +346,7 @@ public abstract class ShadowJar : Jar() { @TaskAction override fun copy() { includedDependencies.files.map { file -> - if (file.extension.equals("aar", ignoreCase = true)) { + if (file.isFile && file.extension.equals("aar", ignoreCase = true)) { val message = """ Shadowing AAR file is not supported. Please exclude dependency artifact: $file From d4ed84d63a16c7dfeef72bfa5f65f74e7b5d0943 Mon Sep 17 00:00:00 2001 From: Goooler Date: Fri, 8 Aug 2025 11:17:19 +0800 Subject: [PATCH 3/7] Test `shadowExposedCustomSourceSetOutput` --- .../gradle/plugins/shadow/JavaPluginsTest.kt | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginsTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginsTest.kt index d2c17cac5..a2c0c90cb 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginsTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginsTest.kt @@ -191,6 +191,53 @@ class JavaPluginsTest : BasePluginTest() { } } + @Issue( + "https://github.com/GradleUp/shadow/issues/1606", + ) + @Test + fun shadowExposedCustomSourceSetOutput() { + writeClientAndServerModules() + path("client/build.gradle").appendText( + """ + sourceSets { + custom + } + dependencies { + api sourceSets.custom.output + } + """.trimIndent(), + ) + path("client/src/custom/java/client/Custom1.java").writeText( + """ + package client; + public class Custom1 {} + """.trimIndent(), + ) + path("client/src/custom/java/client/Custom2.java").writeText( + """ + package client; + public class Custom2 {} + """.trimIndent(), + ) + path("client/src/custom/resources/Foo.bar").writeText("Foo=Bar") + + run(serverShadowJarPath) + + assertThat(outputServerShadowedJar).useAll { + containsOnly( + "client/", + "server/", + "client/Client.class", + "client/Custom1.class", + "client/Custom2.class", + "client/Foo.bar", + "server/Server.class", + *junitEntries, + *manifestEntries, + ) + } + } + @Issue( "https://github.com/GradleUp/shadow/issues/449", ) From 95fab316a224af6b310bb402e3e573b4e73aeed0 Mon Sep 17 00:00:00 2001 From: Goooler Date: Fri, 8 Aug 2025 11:19:59 +0800 Subject: [PATCH 4/7] Add dirs directly without unzipping --- .../github/jengelman/gradle/plugins/shadow/JavaPluginsTest.kt | 4 ++-- .../github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginsTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginsTest.kt index a2c0c90cb..91593960c 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginsTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginsTest.kt @@ -203,7 +203,7 @@ class JavaPluginsTest : BasePluginTest() { custom } dependencies { - api sourceSets.custom.output + implementation sourceSets.custom.output } """.trimIndent(), ) @@ -225,12 +225,12 @@ class JavaPluginsTest : BasePluginTest() { assertThat(outputServerShadowedJar).useAll { containsOnly( + "Foo.bar", "client/", "server/", "client/Client.class", "client/Custom1.class", "client/Custom2.class", - "client/Foo.bar", "server/Server.class", *junitEntries, *manifestEntries, diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt index 41a7173cd..7823ebb97 100644 --- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt +++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt @@ -354,6 +354,10 @@ public abstract class ShadowJar : Jar() { """.trimIndent() error(message) } + if (file.isDirectory) { + from(file) + return@map + } from(archiveOperations.zipTree(file)) } From d1145944585c4b899477a27b9cb5ec7c0ea7ebbb Mon Sep 17 00:00:00 2001 From: Goooler Date: Fri, 8 Aug 2025 11:23:54 +0800 Subject: [PATCH 5/7] Update changelog --- docs/changes/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/changes/README.md b/docs/changes/README.md index ee079a86f..dc11a63ae 100644 --- a/docs/changes/README.md +++ b/docs/changes/README.md @@ -7,6 +7,10 @@ - Improve the error message for empty `mainClassName`. ([#1601](https://github.com/GradleUp/shadow/pull/1601)) +### Fixed + +- Fix the regression of can't shadow directory inputs. ([#1606](https://github.com/GradleUp/shadow/pull/1606)) + ## [9.0.0](https://github.com/GradleUp/shadow/compare/9.0.0) - 2025-08-07 !!! warning From 6a7a9a19f151494138c9b5e5659b5cefe77f4f8c Mon Sep 17 00:00:00 2001 From: Goooler Date: Fri, 8 Aug 2025 11:27:38 +0800 Subject: [PATCH 6/7] Use `when` --- .../gradle/plugins/shadow/tasks/ShadowJar.kt | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt index 7823ebb97..2a6990fd0 100644 --- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt +++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt @@ -346,20 +346,22 @@ public abstract class ShadowJar : Jar() { @TaskAction override fun copy() { includedDependencies.files.map { file -> - if (file.isFile && file.extension.equals("aar", ignoreCase = true)) { - val message = """ + when { + file.isDirectory -> { + from(file) + } + file.extension.equals("aar", ignoreCase = true) -> { + val message = """ Shadowing AAR file is not supported. Please exclude dependency artifact: $file or use Android Fused Library plugin instead. See https://developer.android.com/build/publish-library/fused-library. - """.trimIndent() - error(message) - } - if (file.isDirectory) { - from(file) - return@map + """.trimIndent() + error(message) + } + else -> { + from(archiveOperations.zipTree(file)) + } } - - from(archiveOperations.zipTree(file)) } injectMultiReleaseAttrIfPresent() super.copy() From 7e65d1d0607ba3596aeeac6f3eb5c5e64a87b6bb Mon Sep 17 00:00:00 2001 From: Goooler Date: Fri, 8 Aug 2025 11:31:08 +0800 Subject: [PATCH 7/7] Use `forEach` --- .../github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt index 2a6990fd0..bff26b860 100644 --- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt +++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt @@ -345,7 +345,7 @@ public abstract class ShadowJar : Jar() { @TaskAction override fun copy() { - includedDependencies.files.map { file -> + includedDependencies.files.forEach { file -> when { file.isDirectory -> { from(file)