Repository: GradleUp/shadow
Pull request #1155 (2025-01-14 05:07:43)

Prefer plugins blocks in docs


Patch:
diff --git a/src/docs/application-plugin/README.md b/src/docs/application-plugin/README.md
index c1e8110a..2ce520a9 100644
--- a/src/docs/application-plugin/README.md
+++ b/src/docs/application-plugin/README.md
@@ -9,9 +9,11 @@ configured to contain the `Main-Class` attribute with the value specified in the
 
 ```groovy
 // Using Shadow with Application Plugin
-apply plugin: 'java'
-apply plugin: 'application'
-apply plugin: 'com.gradleup.shadow'
+plugins {
+  id 'java'
+  id 'application'
+  id 'com.gradleup.shadow'
+}
 
 application {
   mainClass = 'myapp.Main'
@@ -28,9 +30,11 @@ 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'
+plugins {
+  id 'java'
+  id 'application'
+  id 'com.gradleup.shadow'
+}
 
 application {
   mainClass = 'myapp.Main'
diff --git a/src/docs/getting-started/README.md b/src/docs/getting-started/README.md
index 6df8741a..ae53b93d 100644
--- a/src/docs/getting-started/README.md
+++ b/src/docs/getting-started/README.md
@@ -19,8 +19,9 @@ buildscript {
   }
 }
 
-apply plugin: 'com.gradleup.shadow'
+// `apply plugin` stuffs are used with `buildscript`.
 apply plugin: 'java'
+apply plugin: 'com.gradleup.shadow'
 ```
 
 <details>
@@ -38,6 +39,7 @@ buildscript {
   }
 }
 
+// `apply plugin` stuffs are used with `buildscript`.
 apply plugin: 'java'
 apply plugin: 'com.gradleup.shadow'
 ```
diff --git a/src/docs/plugins/README.md b/src/docs/plugins/README.md
index e65c9534..d0e107bf 100644
--- a/src/docs/plugins/README.md
+++ b/src/docs/plugins/README.md
@@ -11,8 +11,10 @@ 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-gradle-plugin'
-apply plugin: 'com.gradleup.shadow'
+plugins {
+  id 'java-gradle-plugin'
+  id 'com.gradleup.shadow'
+}
 
 dependencies {
   implementation 'org.jdom:jdom2:2.0.6'
diff --git a/src/docs/publishing/README.md b/src/docs/publishing/README.md
index e912b513..15172841 100644
--- a/src/docs/publishing/README.md
+++ b/src/docs/publishing/README.md
@@ -9,9 +9,11 @@ artifact and dependencies in the POM file.
 
 ```groovy
 // Publishing a Shadow JAR with the Maven-Publish Plugin
-apply plugin: 'java'
-apply plugin: 'maven-publish'
-apply plugin: 'com.gradleup.shadow'
+plugins {
+  id 'java'
+  id 'maven-publish'
+  id 'com.gradleup.shadow'
+}
 
 publishing {
   publications {
@@ -52,9 +54,11 @@ You may want to publish the shadowed JAR instead of the original JAR. This can b
 the `archiveClassifier` of the shadowed JAR like the following:
 
 ```groovy
-apply plugin: 'java'
-apply plugin: 'maven-publish'
-apply plugin: 'com.gradleup.shadow'
+plugins {
+  id 'java'
+  id 'maven-publish'
+  id 'com.gradleup.shadow'
+}
 
 group = 'shadow'
 version = '1.0'


Test patch:
diff --git a/src/integrationTest/kotlin/com/github/jengelman/gradle/plugins/shadow/executor/GroovyBuildExecutor.kt b/src/integrationTest/kotlin/com/github/jengelman/gradle/plugins/shadow/executor/GroovyBuildExecutor.kt
index fbe45440..aac341f2 100644
--- a/src/integrationTest/kotlin/com/github/jengelman/gradle/plugins/shadow/executor/GroovyBuildExecutor.kt
+++ b/src/integrationTest/kotlin/com/github/jengelman/gradle/plugins/shadow/executor/GroovyBuildExecutor.kt
@@ -36,8 +36,10 @@ class GroovyBuildExecutor(
     val mainScript = buildString {
       append(imports)
       append(System.lineSeparator())
-      append(fixture.pre)
-      append(System.lineSeparator())
+      if (!snippetWithoutImports.contains("plugins {")) {
+        append(fixture.pluginsBlock)
+        append(System.lineSeparator())
+      }
       append(snippetWithoutImports)
       append(System.lineSeparator())
     }.trimIndent()
diff --git a/src/integrationTest/kotlin/com/github/jengelman/gradle/plugins/shadow/fixture/GroovyDslFixture.kt b/src/integrationTest/kotlin/com/github/jengelman/gradle/plugins/shadow/fixture/GroovyDslFixture.kt
index 525dbce8..aef8bc17 100644
--- a/src/integrationTest/kotlin/com/github/jengelman/gradle/plugins/shadow/fixture/GroovyDslFixture.kt
+++ b/src/integrationTest/kotlin/com/github/jengelman/gradle/plugins/shadow/fixture/GroovyDslFixture.kt
@@ -2,7 +2,7 @@ package com.github.jengelman.gradle.plugins.shadow.fixture
 
 object GroovyDslFixture : SnippetFixture {
 
-  override val pre: String = """
+  override val pluginsBlock: String = """
     plugins {
       id 'java'
       id 'com.gradleup.shadow'
diff --git a/src/integrationTest/kotlin/com/github/jengelman/gradle/plugins/shadow/fixture/SnippetFixture.kt b/src/integrationTest/kotlin/com/github/jengelman/gradle/plugins/shadow/fixture/SnippetFixture.kt
index 95a2ebf5..d39fc238 100644
--- a/src/integrationTest/kotlin/com/github/jengelman/gradle/plugins/shadow/fixture/SnippetFixture.kt
+++ b/src/integrationTest/kotlin/com/github/jengelman/gradle/plugins/shadow/fixture/SnippetFixture.kt
@@ -1,5 +1,5 @@
 package com.github.jengelman.gradle.plugins.shadow.fixture
 
 interface SnippetFixture {
-  val pre: String
+  val pluginsBlock: String
 }