Search code examples
gradlecocoapodskotlin-native

Kotlin Native Cocoapods plugin - how to specify Podspec source?


Now when generating podspec with Gradle I get

spec.source = { :git => "Not Published", :tag => "Cocoapods/#{spec.name}/#{spec.version}" }

How can I change :git and :tag here in Gradle in cocoapods?

cocoapods {
        // Configure fields required by CocoaPods.
        def projectName = project.getRootProject().getName()
        summary = projectName
        ios.deploymentTarget = "9.0"
        // set git source here?
}

Solution

  • There are no default options for this.

    If you want to change those fields content, you can follow the approach described https://youtrack.jetbrains.com/issue/KT-42105.

    For example, adding this code to your build.gradle.kts might do the trick:

    val podspec = tasks["podspec"] as PodspecTask
    podspec.doLast {
        val podspec = file("${project.name.replace("-", "_")}.podspec")
        val newPodspecContent = podspec.readLines().map {
            if (it.contains("spec.source")) "    spec.source = <some custom value>" else it
        }
        podspec.writeText(newPodspecContent.joinToString(separator = "\n"))
    }
    

    It interprets the podspec file as a text file and allows you to change it as you like to.