Repository: GradleUp/shadow (kotlin)

Issue:
Configuration with name 'shadow' not found.
### Expected and Results

Shadow version: 9.2.1

When switching from 9.1.0 to 9.2.1 build start to fail with: 'Configuration with name 'shadow' not found'

```
Configuration cache state could not be cached: field `shadowDependencies` of task `:taskName` of type `com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar`: error writing value of type 'org.gradle.api.internal.provider.DefaultProvider'
> Configuration with name 'shadow' not found.

```

Code for task registration:
`project.tasks.register("taskName", ShadowJar::class.java) { ... }`

Reproducer project:
https://github.com/hondogo/kotlin-issue-reproducer/tree/shadow

Line of code where shadow task created:
https://github.com/hondogo/kotlin-issue-reproducer/blob/6cc320be324c07c9d93b14fe878d8cbf4e61085d/module1/build.gradle.kts#L27

### Related environment and versions

_No response_

### Reproduction steps

_No response_

### Anything else?

_No response_

Pull request description:
Closes #1784.

---

- [x] [CHANGELOG](https://github.com/GradleUp/shadow/blob/main/docs/changes/README.md)'s "Unreleased" section has been updated, if applicable.

Patch:
diff --git a/docs/changes/README.md b/docs/changes/README.md
index 272e4806e..04b149f67 100644
--- a/docs/changes/README.md
+++ b/docs/changes/README.md
@@ -3,6 +3,9 @@
 
 ## [Unreleased](https://github.com/GradleUp/shadow/compare/9.2.1...HEAD) - 2025-xx-xx
 
+## Fixed
+
+- Fix the regression of registering `ShadowJar` tasks without `ShadowPlugin` applied. ([#1787](https://github.com/GradleUp/shadow/pull/1787))
 
 ## [9.2.1](https://github.com/GradleUp/shadow/compare/9.2.0) - 2025-09-24
 
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 c2e1cc506..685df526c 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
@@ -63,7 +63,10 @@ import org.gradle.language.base.plugins.LifecycleBasePlugin
 @CacheableTask
 public abstract class ShadowJar : Jar() {
   private val dependencyFilterForMinimize = MinimizeDependencyFilter(project)
-  private val shadowDependencies = project.provider { project.files(project.configurations.shadow) }
+  private val shadowDependencies = project.provider {
+    // Find shadow configuration here instead of get, as the ShadowJar tasks could be registered without Shadow plugin applied.
+    project.configurations.findByName(ShadowBasePlugin.CONFIGURATION_NAME) ?: project.files()
+  }
 
   init {
     group = LifecycleBasePlugin.BUILD_GROUP


Test patch:
diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt
index ec6b2eeaa..d5d5917d5 100644
--- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt
+++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt
@@ -144,13 +144,14 @@ abstract class BasePluginTest {
     plugin: String = "java",
     withGroup: Boolean = false,
     withVersion: Boolean = false,
+    applyShadowPlugin: Boolean = true,
   ): String {
     val groupInfo = if (withGroup) "group = 'my'" else ""
     val versionInfo = if (withVersion) "version = '1.0'" else ""
     return """
       plugins {
         id '$plugin'
-        id '$shadowPluginId'
+        id '$shadowPluginId' apply $applyShadowPlugin
       }
       $groupInfo
       $versionInfo
diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginsTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginsTest.kt
index 05e9eb31c..1a4c34fc4 100644
--- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginsTest.kt
+++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginsTest.kt
@@ -604,6 +604,62 @@ class JavaPluginsTest : BasePluginTest() {
     )
   }
 
+  @Issue(
+    "https://github.com/GradleUp/shadow/issues/1784",
+  )
+  @Test
+  fun registerShadowJarTaskWithoutShadowPluginApplied() {
+    val mainClassEntry = writeClass(sourceSet = "test", withImports = true)
+    val testShadowJarTask = "testShadowJar"
+    projectScript.writeText(
+      """
+        ${getDefaultProjectBuildScript(withGroup = true, withVersion = true, applyShadowPlugin = false)}
+        dependencies {
+          testImplementation 'junit:junit:3.8.2'
+        }
+        def $testShadowJarTask = tasks.register('$testShadowJarTask', ${ShadowJar::class.java.name}) {
+          description = 'Create a combined JAR of project and test dependencies'
+          archiveClassifier = 'test'
+          from sourceSets.named('test').map { it.output }
+          configurations = project.configurations.named('testRuntimeClasspath').map { [it] }
+          manifest {
+            attributes '$mainClassAttributeKey': 'my.Main'
+          }
+        }
+        afterEvaluate {
+          def hasShadowPlugin = plugins.hasPlugin('${ShadowPlugin::class.qualifiedName}')
+          def hasShadowBasePlugin = plugins.hasPlugin('${ShadowBasePlugin::class.qualifiedName}')
+          logger.lifecycle("Has ShadowPlugin: " + hasShadowPlugin)
+          logger.lifecycle("Has ShadowBasePlugin: " + hasShadowBasePlugin)
+        }
+      """.trimIndent(),
+    )
+
+    val result = run(testShadowJarTask)
+
+    assertThat(result.output).contains(
+      "Has ShadowPlugin: false",
+      "Has ShadowBasePlugin: false",
+    )
+
+    assertThat(jarPath("build/libs/my-1.0-test.jar")).useAll {
+      containsOnly(
+        "my/",
+        mainClassEntry,
+        *junitEntries,
+        *manifestEntries,
+      )
+      getMainAttr(mainClassAttributeKey).isNotNull()
+    }
+
+    val pathString = path("build/libs/my-1.0-test.jar").toString()
+    val runningOutput = runProcess("java", "-jar", pathString, "foo")
+    assertThat(runningOutput).contains(
+      "Hello, World! (foo) from Main",
+      "Refs: junit.framework.Test",
+    )
+  }
+
   @Issue(
     "https://github.com/GradleUp/shadow/issues/443",
   )