From 2283c52e6a9cbd642f439c67610792d90938eb17 Mon Sep 17 00:00:00 2001 From: Goooler Date: Thu, 5 Mar 2026 09:54:34 +0800 Subject: [PATCH] Add extendsFromCompat for Configuration https://docs.gradle.org/9.4.0/release-notes.html#build-authoring --- .../jengelman/gradle/plugins/shadow/ShadowJavaPlugin.kt | 7 ++++--- .../gradle/plugins/shadow/internal/GradleCompat.kt | 9 +++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.kt index 3be275cd3..79e67df3b 100644 --- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.kt +++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.kt @@ -3,6 +3,7 @@ package com.github.jengelman.gradle.plugins.shadow import com.github.jengelman.gradle.plugins.shadow.ShadowBasePlugin.Companion.SHADOW import com.github.jengelman.gradle.plugins.shadow.ShadowBasePlugin.Companion.shadow import com.github.jengelman.gradle.plugins.shadow.internal.addVariantsFromConfigurationCompat +import com.github.jengelman.gradle.plugins.shadow.internal.extendsFromCompat import com.github.jengelman.gradle.plugins.shadow.internal.javaPluginExtension import com.github.jengelman.gradle.plugins.shadow.internal.moveGradleApiIntoCompileOnly import com.github.jengelman.gradle.plugins.shadow.internal.runtimeConfiguration @@ -47,13 +48,13 @@ constructor(private val softwareComponentFactory: SoftwareComponentFactory) : Pl } protected open fun Project.configureConfigurations() { - val shadowConfiguration = configurations.shadow.get() + val shadowConfiguration = configurations.shadow configurations.named(COMPILE_CLASSPATH_CONFIGURATION_NAME) { compileClasspath -> - compileClasspath.extendsFrom(shadowConfiguration) + compileClasspath.extendsFromCompat(shadowConfiguration) } val shadowRuntimeElements = configurations.register(SHADOW_RUNTIME_ELEMENTS_CONFIGURATION_NAME) { - it.extendsFrom(shadowConfiguration) + it.extendsFromCompat(shadowConfiguration) it.isCanBeConsumed = true it.isCanBeResolved = false it.attributes { attrs -> diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/GradleCompat.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/GradleCompat.kt index bdccf7d3e..bb8dcbf69 100644 --- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/GradleCompat.kt +++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/GradleCompat.kt @@ -67,6 +67,15 @@ internal fun Project.addBuildScanCustomValues() { } } +/** TODO: this could be removed after bumping the min Gradle requirement to 9.4 or above. */ +internal fun Configuration.extendsFromCompat(vararg superConfigs: Provider) { + if (GradleVersion.current() >= GradleVersion.version("9.4.0")) { + @Suppress("UnstableApiUsage") extendsFrom(*superConfigs) + } else { + extendsFrom(*superConfigs.map { it.get() }.toTypedArray()) + } +} + /** TODO: this could be removed after bumping the min Gradle requirement to 9.2 or above. */ @Suppress("UnstableApiUsage") internal fun AdhocComponentWithVariants.addVariantsFromConfigurationCompat(