From d47fad55bbb993d54b5af5d7b4a06b37b2e587ca Mon Sep 17 00:00:00 2001 From: Martin Bonnin Date: Mon, 21 Dec 2020 10:48:51 +0100 Subject: [PATCH] For recent versions of Gradle, use .convention to provide the default (#2803) This allows to call `customTypeMap.put()` --- .../gradle/internal/DefaultCompilerParams.kt | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo/gradle/internal/DefaultCompilerParams.kt b/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo/gradle/internal/DefaultCompilerParams.kt index b912575df95..6f3fca42a08 100644 --- a/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo/gradle/internal/DefaultCompilerParams.kt +++ b/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo/gradle/internal/DefaultCompilerParams.kt @@ -8,6 +8,7 @@ import org.gradle.api.provider.ListProperty import org.gradle.api.provider.MapProperty import org.gradle.api.provider.Property import org.gradle.api.provider.SetProperty +import org.gradle.util.GradleVersion import javax.inject.Inject abstract class DefaultCompilerParams @Inject constructor(objects: ObjectFactory) : CompilerParams { @@ -42,11 +43,16 @@ abstract class DefaultCompilerParams @Inject constructor(objects: ObjectFactory) abstract override val alwaysGenerateTypesMatching: SetProperty init { - // see https://github.com/gradle/gradle/issues/7485 - // TODO replace with `convention(null)` when we can target Gradle 6.2 - customTypeMapping.set(null as Map?) - sealedClassesForEnumsMatching.set(null as List?) - alwaysGenerateTypesMatching.set(null as Set?) + if (GradleVersion.current() >= GradleVersion.version("6.2")) { + // This allows users to call customTypeMapping.put("Date", "java.util.Date") + // see https://github.com/gradle/gradle/issues/7485 + customTypeMapping.convention(null as Map?) + sealedClassesForEnumsMatching.convention(null as List?) + alwaysGenerateTypesMatching.convention(null as Set?) + } else { + customTypeMapping.set(null as Map?) + sealedClassesForEnumsMatching.set(null as List?) + alwaysGenerateTypesMatching.set(null as Set?) + } } - }