From 4f35e0359c107caa0e0317d963620ba782c4fb06 Mon Sep 17 00:00:00 2001 From: Goooler Date: Wed, 22 Jul 2026 08:53:48 +0800 Subject: [PATCH] Extract addIncludedDependencies --- .../gradle/plugins/shadow/tasks/ShadowJar.kt | 50 ++++++++++--------- 1 file changed, 27 insertions(+), 23 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 1edf8ff0d..b4e6aa199 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 @@ -508,29 +508,7 @@ public abstract class ShadowJar : Jar() { @TaskAction override fun copy() { - includedDependencies.files.forEach { file -> - when { - !file.exists() -> { - logger.info("Skipping non-existent dependency: {}", file) - } - file.isDirectory -> { - from(file) - } - file.extension.equals("aar", ignoreCase = true) && file.isAar() -> { - 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() - throw GradleException(message) - } - else -> { - from(archiveOperations.zipTree(file)) - } - } - } + addIncludedDependencies() injectManifestAttributes() super.copy() minimizeWithR8() @@ -635,6 +613,32 @@ public abstract class ShadowJar : Jar() { } } + private fun addIncludedDependencies() { + includedDependencies.files.forEach { file -> + when { + !file.exists() -> { + logger.info("Skipping non-existent dependency: {}", file) + } + file.isDirectory -> { + from(file) + } + file.extension.equals("aar", ignoreCase = true) && file.isAar() -> { + 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() + throw GradleException(message) + } + else -> { + from(archiveOperations.zipTree(file)) + } + } + } + } + private fun injectManifestAttributes() { val mainClassValue = mainClass.orNull when {