From 2865ddd6af67def4c7a7113963a6cfc78e023abb Mon Sep 17 00:00:00 2001 From: Matt Groth Date: Tue, 12 Nov 2024 11:07:17 -0500 Subject: [PATCH] Fix deprecation warning for `forUseAtConfigurationTime` (#5162) `forUseAtConfigurationTime` is a no-op starting at Gradle 7.4, so it can safely not be used starting at this version. This will have no affect other than to prevent a deprecation warning for those using newer gradle versions. Describe proposed changes and the issue being fixed Fixes https://youtrack.jetbrains.com/issue/CMP-3945/The-Provider.forUseAtConfigurationTime-method-has-been-deprecated --- .../compose/internal/utils/providerUtils.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/internal/utils/providerUtils.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/internal/utils/providerUtils.kt index 11455838da..2614dc6094 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/internal/utils/providerUtils.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/internal/utils/providerUtils.kt @@ -12,6 +12,7 @@ import org.gradle.api.provider.Property import org.gradle.api.provider.Provider import org.gradle.api.provider.ProviderFactory import org.jetbrains.kotlin.gradle.plugin.extraProperties +import org.gradle.util.GradleVersion internal inline fun ObjectFactory.new(vararg params: Any): T = newInstance(T::class.java, *params) @@ -38,11 +39,13 @@ internal fun ProviderFactory.valueOrNull(prop: String): Provider = } private fun Provider.forUseAtConfigurationTimeSafe(): Provider = - try { - forUseAtConfigurationTime() - } catch (e: NoSuchMethodError) { - // todo: remove once we drop support for Gradle 6.4 + // forUseAtConfigurationTime is a no-op starting at Gradle 7.4 and just produces deprecation warnings. + // See https://docs.gradle.org/current/kotlin-dsl/gradle/org.gradle.api.provider/-provider/for-use-at-configuration-time.html + if (GradleVersion.current() >= GradleVersion.version("7.4")) { this + } else { + // todo: remove once we drop support for Gradle 6.4 + forUseAtConfigurationTime() } internal fun Provider.toBooleanProvider(defaultValue: Boolean): Provider = @@ -51,4 +54,4 @@ internal fun Provider.toBooleanProvider(defaultValue: Boolean): Provide internal fun Project.findLocalOrGlobalProperty(name: String, default: String = ""): Provider = provider { if (extraProperties.has(name)) extraProperties.get(name).toString() else providers.gradleProperty(name).forUseAtConfigurationTimeSafe().getOrElse(default) -} \ No newline at end of file +}