From fd825e0601b3b29bd22342737a823674d779e09d Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Wed, 20 Mar 2019 16:00:23 +0700 Subject: [PATCH] CocoaPods: Detect the real path to Gradle wrapper. Previously the CocoaPods plugin assumed that Gradle wrapper is located in the project directory. But the project may be a part of multiproject build and wrapper may be located in the root directory of such a build. Also the build may not have the wrapper at all. This patch looks for the wrapper in the root directory of the build and runs the local Gradle if there is no wrapper. --- .../jetbrains/kotlin/gradle/tasks/CocoapodsTasks.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/CocoapodsTasks.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/CocoapodsTasks.kt index 1411fac09d9..e1494c2d681 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/CocoapodsTasks.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/CocoapodsTasks.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.gradle.tasks import org.gradle.api.DefaultTask import org.gradle.api.tasks.* +import org.gradle.api.tasks.wrapper.Wrapper import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin.Companion.KOTLIN_TARGET_FOR_DEVICE @@ -38,6 +39,14 @@ open class PodspecTask : DefaultTask() { "| spec.dependency '${pod.name}'$versionSuffix" }.joinToString(separator = "\n") + // Try to construct a path to Gradle wrapper. If there is no wrapper, just run the local Gradle. + val gradleWrapper = (project.rootProject.tasks.getByName("wrapper") as? Wrapper)?.scriptFile + val gradleCommand = if (gradleWrapper != null && gradleWrapper.exists()) { + "\$REPO_ROOT/${gradleWrapper.toRelativeString(project.projectDir)}" + } else { + "gradle" + } + outputFile.writeText(""" |Pod::Spec.new do |spec| | spec.name = '$specName' @@ -69,7 +78,7 @@ open class PodspecTask : DefaultTask() { | :script => <<-SCRIPT | set -ev | REPO_ROOT="${'$'}PODS_TARGET_SRCROOT" - | ${'$'}REPO_ROOT/gradlew -p "${'$'}REPO_ROOT" syncFramework \ + | "$gradleCommand" -p "${'$'}REPO_ROOT" syncFramework \ | -P${KotlinCocoapodsPlugin.TARGET_PROPERTY}=${'$'}KOTLIN_TARGET \ | -P${KotlinCocoapodsPlugin.CONFIGURATION_PROPERTY}=${'$'}CONFIGURATION \ | -P${KotlinCocoapodsPlugin.CFLAGS_PROPERTY}="${'$'}OTHER_CFLAGS" \