Repository: GradleUp/shadow
Pull request #1124 (2025-01-01 06:40:33)

Polish doc tests


Patch:
diff --git a/src/docs/application-plugin/README.md b/src/docs/application-plugin/README.md
index 60acd35c..c1e8110a 100644
--- a/src/docs/application-plugin/README.md
+++ b/src/docs/application-plugin/README.md
@@ -28,6 +28,14 @@ It can be configured the same as any other `JavaExec` task.
 
 ```groovy
 // Configuring the runShadow Task
+apply plugin: 'java'
+apply plugin: 'application'
+apply plugin: 'com.gradleup.shadow'
+
+application {
+  mainClass = 'myapp.Main'
+}
+
 tasks.named('runShadow', com.github.jengelman.gradle.plugins.shadow.tasks.JavaJarExec) {
   args 'foo'
 }
diff --git a/src/docs/configuration/reproducible-builds/README.md b/src/docs/configuration/reproducible-builds/README.md
index 79f7505e..aaec5858 100644
--- a/src/docs/configuration/reproducible-builds/README.md
+++ b/src/docs/configuration/reproducible-builds/README.md
@@ -3,7 +3,7 @@
 By default, JAR files generated by Gradle (with or without Shadow) for a single project with the same source code may not be identical to each other. Sometimes it's desireable to configure a project to consistently output a byte-for-byte identical JAR on every build. Gradle supports this with the following configuration, and Shadow will correctly respect these settings too:
 
 ```groovy
-tasks.withType(AbstractArchiveTask) {
+tasks.withType(AbstractArchiveTask).configureEach {
   preserveFileTimestamps = false
   reproducibleFileOrder = true
 }
diff --git a/src/docs/getting-started/README.md b/src/docs/getting-started/README.md
index 8963fe0a..6df8741a 100644
--- a/src/docs/getting-started/README.md
+++ b/src/docs/getting-started/README.md
@@ -2,8 +2,8 @@
 
 ```groovy no-run
 plugins {
-  id 'com.gradleup.shadow' version '@version@'
   id 'java'
+  id 'com.gradleup.shadow' version '@version@'
 }
 ```
 
@@ -38,8 +38,8 @@ buildscript {
   }
 }
 
-apply plugin: 'com.gradleup.shadow'
 apply plugin: 'java'
+apply plugin: 'com.gradleup.shadow'
 ```
 
 </p>
diff --git a/src/docs/plugins/README.md b/src/docs/plugins/README.md
index 2ea99dd7..b4b6a484 100644
--- a/src/docs/plugins/README.md
+++ b/src/docs/plugins/README.md
@@ -11,9 +11,6 @@ and `relocationPrefix` settings on any `ShadowJar` task.
 A simple Gradle plugin can use this feature by applying the `shadow` plugin and configuring the `shadowJar` task for relocation.
 
 ```groovy
-apply plugin: 'java'
-apply plugin: 'com.gradleup.shadow'
-
 dependencies {
   shadow localGroovy()
   shadow gradleApi()
diff --git a/src/docs/publishing/README.md b/src/docs/publishing/README.md
index 596fe3ee..d87ccf8f 100644
--- a/src/docs/publishing/README.md
+++ b/src/docs/publishing/README.md
@@ -21,7 +21,7 @@ publishing {
   }
   repositories {
     maven {
-      url "https://repo.myorg.com"
+      url = "https://repo.myorg.com"
     }
   }
 }


Test patch:
diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/doc/executor/GroovyBuildExecutor.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/doc/executor/GroovyBuildExecutor.kt
index 68c2dc7e..556f93fb 100644
--- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/doc/executor/GroovyBuildExecutor.kt
+++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/doc/executor/GroovyBuildExecutor.kt
@@ -5,32 +5,53 @@ import java.nio.file.Path
 import kotlin.io.path.createDirectory
 import kotlin.io.path.writeText
 import org.gradle.testkit.runner.GradleRunner
-import org.intellij.lang.annotations.Language
 
 class GroovyBuildExecutor(
   override val fixture: SnippetFixture,
   private val importExtractor: (String) -> List<String>,
-  private val arguments: Array<String> = arrayOf("build", "-m"),
 ) : SnippetExecutor {
 
   override fun execute(tempDir: Path, snippet: String) {
-    tempDir.resolve("settings.gradle").writeText(settingsBuildText)
-    tempDir.addSubProject("api", projectBuildText)
+    tempDir.resolve("settings.gradle").writeText(
+      """
+        dependencyResolutionManagement {
+          repositories {
+            mavenLocal()
+            mavenCentral()
+          }
+        }
+        include 'api', 'main'
+      """.trimIndent(),
+    )
 
-    val (imports, snippetWithoutImports) = importExtractor(snippet)
-    val fullSnippet = imports + fixture.pre + '\n' + snippetWithoutImports + '\n' + fixture.post
+    val apiScript = """
+      plugins {
+        id 'java'
+        id 'com.gradleup.shadow'
+      }
+    """.trimIndent()
+    tempDir.addSubProject("api", apiScript)
 
-    tempDir.addSubProject("main", fullSnippet)
+    val (imports, snippetWithoutImports) = importExtractor(snippet)
+    val mainScript = buildString {
+      append(imports)
+      append(System.lineSeparator())
+      append(fixture.pre)
+      append(System.lineSeparator())
+      append(snippetWithoutImports)
+      append(System.lineSeparator())
+    }.trimIndent()
+    tempDir.addSubProject("main", mainScript)
 
     try {
       GradleRunner.create()
         .withProjectDir(tempDir.toFile())
         .withPluginClasspath()
         .forwardOutput()
-        .withArguments(*arguments)
+        .withArguments("--warning-mode=fail", "build")
         .build()
     } catch (t: Throwable) {
-      throw RuntimeException("Failed to execute snippet:\n\n$fullSnippet", t)
+      throw RuntimeException("Failed to execute snippet:\n\n$mainScript", t)
     }
   }
 
@@ -40,24 +61,4 @@ class GroovyBuildExecutor(
       .resolve("build.gradle")
       .writeText(buildScriptText)
   }
-
-  private companion object {
-    @Language("Groovy")
-    private val settingsBuildText = """
-      rootProject.name = 'shadowTest'
-      include 'api', 'main'
-    """.trimIndent()
-
-    @Language("Groovy")
-    private val projectBuildText = """
-      plugins {
-        id 'java'
-        id 'com.gradleup.shadow'
-      }
-      repositories {
-        mavenLocal()
-        mavenCentral()
-      }
-    """.trimIndent()
-  }
 }
diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/doc/fixture/GroovyDslFixture.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/doc/fixture/GroovyDslFixture.kt
index b4e60e4c..e7dacf74 100644
--- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/doc/fixture/GroovyDslFixture.kt
+++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/doc/fixture/GroovyDslFixture.kt
@@ -1,26 +1,14 @@
 package com.github.jengelman.gradle.plugins.shadow.doc.fixture
 
-import org.intellij.lang.annotations.Language
-
 object GroovyDslFixture : SnippetFixture {
 
-  @Language("Groovy")
   override val pre: String = """
     plugins {
-      id("java")
-      id("com.gradleup.shadow")
-      id("application")
-    }
-    repositories {
-      mavenLocal()
-      mavenCentral()
+      id 'java'
+      id 'com.gradleup.shadow'
     }
-    version = "1.0"
-    group = "shadow"
   """.trimIndent()
 
-  override val post: String = ""
-
   val importsExtractor: (String) -> List<String> = { snippet ->
     val imports = StringBuilder()
     val scriptMinusImports = StringBuilder()
diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/doc/fixture/SnippetFixture.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/doc/fixture/SnippetFixture.kt
index a554ad20..8a20af06 100644
--- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/doc/fixture/SnippetFixture.kt
+++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/doc/fixture/SnippetFixture.kt
@@ -2,6 +2,4 @@ package com.github.jengelman.gradle.plugins.shadow.doc.fixture
 
 interface SnippetFixture {
   val pre: String
-
-  val post: String
 }