[Gradle] Sync ListProperty, SetProperty and MapProperty types as non-convention

Such approach, while does not conform conceptually, ensures
compatibility with existing user build scripts and works more logically
for external users: https://github.com/gradle/gradle/issues/18352

^KT-59056 Fixed
This commit is contained in:
Yahor Berdnikau
2023-06-04 23:04:41 +02:00
committed by Space Team
parent 48484368c7
commit 67090ff10a
7 changed files with 101 additions and 37 deletions
@@ -720,9 +720,24 @@ private fun Printer.generateCompilerOptionsHelper(
}
println(") {")
withIndent {
val multiValuesReturnTypes = setOf(
"org.gradle.api.provider.ListProperty",
"org.gradle.api.provider.SetProperty",
)
if (parentHelperName != null) println("$parentHelperName.syncOptionsAsConvention(from, into)")
for (property in properties) {
println("into.${property.name}.convention(from.${property.name})")
// Behaviour of ListProperty, SetProperty, MapProperty append operators in regard to convention value
// is confusing for users: https://github.com/gradle/gradle/issues/18352
// To make it less confusing for such types instead of wiring them via ".convention()" we updating
// current value
val gradleLazyReturnType = property.gradleLazyReturnType
val mapper = when {
multiValuesReturnTypes.any { gradleLazyReturnType.startsWith(it) } -> "addAll"
gradleLazyReturnType.startsWith("org.gradle.api.provider.MapProperty") -> "putAll"
else -> "convention"
}
println("into.${property.name}.$mapper(from.${property.name})")
}
}
println("}")