Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecation warning for forUseAtConfigurationTime #5162

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 <reified T> ObjectFactory.new(vararg params: Any): T =
newInstance(T::class.java, *params)
Expand All @@ -38,11 +39,13 @@ internal fun ProviderFactory.valueOrNull(prop: String): Provider<String?> =
}

private fun Provider<String?>.forUseAtConfigurationTimeSafe(): Provider<String?> =
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<String?>.toBooleanProvider(defaultValue: Boolean): Provider<Boolean> =
Expand All @@ -51,4 +54,4 @@ internal fun Provider<String?>.toBooleanProvider(defaultValue: Boolean): Provide
internal fun Project.findLocalOrGlobalProperty(name: String, default: String = ""): Provider<String> = provider {
if (extraProperties.has(name)) extraProperties.get(name).toString()
else providers.gradleProperty(name).forUseAtConfigurationTimeSafe().getOrElse(default)
}
}
Loading