Skip to content

Commit 85ba389

Browse files
CopilotGoooler
andauthored
Fix failing for non-existent class directories (#1976)
* Initial plan * fix: skip non-existent dependency directories in shadowJar task Fixes #1975. When a project dependency includes a class output directory that does not exist (e.g., build/classes/java/api from a custom source set with no Java sources), shadowJar now gracefully skips it instead of failing with "Cannot expand ZIP ... as it does not exist." Also adds a functional test to verify the fix. Co-authored-by: Goooler <10363352+Goooler@users.noreply.github.com> * Logging for info level * Update changelog --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Goooler <10363352+Goooler@users.noreply.github.com> Co-authored-by: Goooler <wangzongler@gmail.com>
1 parent 3a24369 commit 85ba389

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

docs/changes/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
- Fix interaction with Gradle artifact transforms. ([#1345](https://github.com/GradleUp/shadow/pull/1345))
2424
- Fix `skipStringConstants` per-relocator behavior in `mapName`. ([#1968](https://github.com/GradleUp/shadow/pull/1968))
25+
- Fix failing for non-existent class directories. ([#1976](https://github.com/GradleUp/shadow/pull/1976))
2526

2627
## [9.3.2](https://github.com/GradleUp/shadow/releases/tag/9.3.2) - 2026-02-27
2728

src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginsTest.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,25 @@ class JavaPluginsTest : BasePluginTest() {
813813
}
814814
}
815815

816+
@Issue("https://github.com/GradleUp/shadow/issues/1975")
817+
@Test
818+
fun skipNonExistentDependencyDirectory() {
819+
val nonExistentDir = projectRoot.resolve("non-existent-dir")
820+
821+
projectScript.appendText(
822+
"""
823+
dependencies {
824+
${implementationFiles(nonExistentDir)}
825+
}
826+
"""
827+
.trimIndent()
828+
)
829+
830+
val result = runWithSuccess(shadowJarPath)
831+
832+
assertThat(result.task(shadowJarPath)).isNotNull().transform { it.outcome }.isEqualTo(SUCCESS)
833+
}
834+
816835
@Issue("https://github.com/GradleUp/shadow/issues/915")
817836
@Test
818837
fun failBuildIfProcessingBadJar() {

src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,9 @@ public abstract class ShadowJar : Jar() {
451451
override fun copy() {
452452
includedDependencies.files.forEach { file ->
453453
when {
454+
!file.exists() -> {
455+
logger.info("Skipping non-existent dependency: {}", file)
456+
}
454457
file.isDirectory -> {
455458
from(file)
456459
}

0 commit comments

Comments
 (0)