Repository: GradleUp/shadow
Pull request #1185 (2025-01-24 13:47:49)

Show how to add extra files into distributions
Refs #312.



Patch:
diff --git a/src/docs/application-plugin/README.md b/src/docs/application-plugin/README.md
index 2ce520a9..5534c4ae 100644
--- a/src/docs/application-plugin/README.md
+++ b/src/docs/application-plugin/README.md
@@ -55,3 +55,28 @@ the application.
 
 Additionally, the plugin will create the `installShadowDist` and `startShadowScripts` tasks which stages the necessary
 files for a distribution to `build/install/<project name>-shadow/`.
+
+You can also add more files into the distribution like:
+
+```groovy
+// Add extra files to the distribution
+plugins {
+  id 'java'
+  id 'application'
+  id 'com.gradleup.shadow'
+}
+
+application {
+  mainClass = 'myapp.Main'
+}
+
+// `shadow` is the name of the distribution created by Shadow plugin
+distributions.named('shadow') {
+  contents.into('extra') {
+    from project.file('extra/echo.sh')
+  }
+}
+```
+
+View [the official doc described](https://docs.gradle.org/current/userguide/distribution_plugin.html#distribution_plugin)
+for more information about configuring distributions.


Test patch:
diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationPluginTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationPluginTest.kt
index 442da2e2..2e3e8888 100644
--- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationPluginTest.kt
+++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationPluginTest.kt
@@ -6,9 +6,11 @@ import assertk.assertions.containsOnly
 import assertk.assertions.isEqualTo
 import com.github.jengelman.gradle.plugins.shadow.ShadowApplicationPlugin.Companion.SHADOW_INSTALL_TASK_NAME
 import com.github.jengelman.gradle.plugins.shadow.ShadowApplicationPlugin.Companion.SHADOW_RUN_TASK_NAME
+import com.github.jengelman.gradle.plugins.shadow.ShadowBasePlugin.Companion.DISTRIBUTION_NAME
 import com.github.jengelman.gradle.plugins.shadow.util.Issue
 import com.github.jengelman.gradle.plugins.shadow.util.JarPath
 import com.github.jengelman.gradle.plugins.shadow.util.containsEntries
+import com.github.jengelman.gradle.plugins.shadow.util.getContent
 import com.github.jengelman.gradle.plugins.shadow.util.getMainAttr
 import com.github.jengelman.gradle.plugins.shadow.util.isWindows
 import com.github.jengelman.gradle.plugins.shadow.util.runProcess
@@ -190,6 +192,35 @@ class ApplicationPluginTest : BasePluginTest() {
     )
   }
 
+  @Test
+  fun canAddExtraFilesIntoDistribution() {
+    path("extra/echo.sh").writeText("echo 'Hello, World!'")
+    prepare(
+      projectBlock = """
+        distributions.named('$DISTRIBUTION_NAME') {
+          contents.into('extra') {
+            from project.file('extra/echo.sh')
+          }
+        }
+      """.trimIndent(),
+    )
+
+    run("shadowDistZip")
+
+    val zipPath = path("build/distributions/myapp-shadow-1.0.zip")
+    ZipFile(zipPath.toFile()).use { zip ->
+      val entries = zip.entries().toList().filter { !it.isDirectory }.map { it.name }
+      assertThat(entries).containsOnly(
+        "myapp-shadow-1.0/bin/myapp",
+        "myapp-shadow-1.0/bin/myapp.bat",
+        "myapp-shadow-1.0/lib/myapp-1.0-all.jar",
+        "myapp-shadow-1.0/extra/echo.sh",
+      )
+      assertThat(zip.getContent("myapp-shadow-1.0/extra/echo.sh"))
+        .isEqualTo("echo 'Hello, World!'")
+    }
+  }
+
   private fun prepare(
     mainClassWithImports: Boolean = false,
     projectBlock: String = "",