From de8d4e9e3c8320bcb79276fbb02446fc3b4018b2 Mon Sep 17 00:00:00 2001 From: Yahor Berdnikau Date: Thu, 30 Sep 2021 11:29:31 +0200 Subject: [PATCH] Fix reflection call is not working on older Gradle versions. It happens, older Gradle versions has two functions with the same name, but different parameters. --- .../org/jetbrains/kotlin/gradle/plugin/KotlinPlugin.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinPlugin.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinPlugin.kt index 9ecc33bafbd..8e66930930f 100755 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinPlugin.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinPlugin.kt @@ -462,7 +462,13 @@ internal abstract class AbstractKotlinPlugin( .call(mavenResolver)!! mavenPom::class .functions - .first { it.name == "withXml" } + .first { func -> + // On older Gradle versions there were two 'withXml' method - one with 'Closure' and one with 'Action' + func.name == "withXml" && + func.parameters.any { + it.type.toString() == "org.gradle.api.Action!" + } + } .call(mavenPom, Action { xml -> if (shouldRewritePoms.get()) { pomRewriter.rewritePomMppDependenciesToActualTargetModules(xml)