Add conventions only if they are still available

So Gradle could drop conventions in Gradle 8.0 release.

^KT-47047 Fixed
This commit is contained in:
Yahor Berdnikau
2022-06-22 09:56:36 +02:00
parent 2260893142
commit a85490ea7d
@@ -23,7 +23,18 @@ import org.gradle.api.plugins.ExtensionAware
@Deprecated("Conventions are deprecated in Gradle")
internal inline fun <reified T : Any> Any.addConvention(name: String, plugin: T) {
(this as HasConvention).convention.plugins[name] = plugin
// Verifying conventions are still available via reflection,
// so Gradle could remove them in Gradle 8.0 release
val conventionsIsAvailable = try {
Class.forName("org.gradle.api.internal.HasConvention")
true
} catch (_: ClassNotFoundException) {
false
}
if (conventionsIsAvailable) {
(this as HasConvention).convention.plugins[name] = plugin
}
}
internal inline fun <reified T : Any> Any.addExtension(name: String, extension: T) =