Hey everyone, I’m trying to create a Gradle Conven...
# multiplatform
v
Hey everyone, I’m trying to create a Gradle Convention Plugin for Kotlin Multiplatform but getting this error on
CocoapodsExtension
Copy code
Extension of type 'CocoapodsExtension' does not exist. Currently registered extension types: [ExtraPropertiesExtension, LibrariesForAndroidLibs, LibrariesForLibs, VersionCatalogsExtension, KotlinMultiplatformExtension, KotlinTestsRegistry, BasePluginExtension, DefaultArtifactPublicationSet, SourceSetContainer, ReportingExtension, JavaToolchainService, JavaPluginExtension, KotlinArtifactsExtensionImpl, LibraryExtension, LibraryAndroidComponentsExtension, NamedDomainObjectContainer<BaseVariantOutput>]
This is my plugin
Copy code
class KotlinMultiplatformPlugin: Plugin<Project> {

    override fun apply(target: Project):Unit = with(target){
        with(pluginManager){
            apply(libs.findPlugin("kotlinMultiplatform").get().get().pluginId)
            apply(libs.findPlugin("kotlinCocoapods").get().get().pluginId)
            apply(libs.findPlugin("androidLibrary").get().get().pluginId)
            apply(libs.findPlugin("kotlin.serialization").get().get().pluginId)
        }

        extensions.configure<CocoapodsExtension> {
            configureKotlinCocoapods(this)
        }

        extensions.configure<KotlinMultiplatformExtension>(::configureKotlinMultiplatform)
        extensions.configure<LibraryExtension>(::configureKotlinAndroid)
    }
}
Have also tried to access it inside
KotlinMultiplatformExtension
but cannot access
cocoapods {}
m
This error means that
cocoapods
plugin isn't on your classpath. Make sure to add it in the root
build.gradle.kts
file:
Copy code
plugins {
    alias(libs.plugins.kotlinCocoapods).apply(false)
}
Then in your convention plugin you'll be able to apply it and access
CocoapodsExtension
normally.
v
@MR3Y I already have this in my project
build.gradle.kts
m
Are you also adding it as a dependency in your convention plugin's
build.gradle.kts
? like this:
Copy code
dependencies {
    compileOnly(libs.cocoapods)
}
Note that the dependency coordinates for the gradle plugin here is different from what you add in the root
build.gradle.kts
v
@MR3Y haven’t tried this What’s the artifact coordinate?
m
I mean the dependency coordinates (e.g "groupIdartifactversion"), for example you declare android applicaton gradle plugin like this to use it in your project's build script files:
Copy code
androidApplication = "com.android.application:8.2.0"
but to use it in your convention plugin's
build.gradle.kts
as a dependency in
dependencies
block, you have to declare it like:
Copy code
android-gradlePlugin = "com.android.tools.build:gradle:8.2.0"
v
Whats the same for cocoapods Tried this
org.jetbrains.kotlin:kotlin-native-cocoapods-gradle-plugin
Says cannot resolve
https://plugins.gradle.org/plugin/org.jetbrains.kotlin.native.cocoapods This shows the same which Ive already applied for KMP
m
I'm not familiar with cocoapods plugin, but you have to find the maven coordinates for it. like any other normal library dependency.
Try this: "org.jetbrains.kotlinkotlin gradle plugin2.0.0-Beta2"
Substitute the version with yours
v
already have this applied
Copy code
compileOnly(libs.kotlin.gradlePlugin)
v
Trying this
@MR3Y still the same error
m
what are the coordinates you've used? for cocoapod?
v
Copy code
kotlin-cocoapods-gradlePlugin = { group = "org.jetbrains.kotlin.native.cocoapods", name = "org.jetbrains.kotlin.native.cocoapods.gradle.plugin", version.ref = "kotlin" }
m
what if you changed the group to "org.jetbrains.kotlin" ?
v
Then i get
Copy code
Could not find org.jetbrains.kotlin:org.jetbrains.kotlin.native.cocoapods.gradle.plugin:1.9.20.
same for
Copy code
Could not find org.jetbrains.kotlin:native.cocoapods.gradle.plugin:1.9.20.
m
and what error you were getting previously? can't resolve?
v
Copy code
Extension of type 'CocoapodsExtension' does not exist. Currently registered extension types: [ExtraPropertiesExtension, LibrariesForAndroidLibs, LibrariesForLibs, VersionCatalogsExtension, KotlinMultiplatformExtension, KotlinTestsRegistry, BasePluginExtension, DefaultArtifactPublicationSet, SourceSetContainer, ReportingExtension, JavaToolchainService, JavaPluginExtension, KotlinArtifactsExtensionImpl, LibraryExtension, LibraryAndroidComponentsExtension, NamedDomainObjectContainer<BaseVariantOutput>]
m
So, it successfully resolves the dependency
v
yes
it was resolved even before adding the dependency of gradle plugin
This is the signature of cocoapods {}
Copy code
public fun KotlinMultiplatformExtension.cocoapods(
    configure: Action<CocoapodsExtension>
): Unit

org.gradle.kotlin.dsl   Accessors2zy97bxtvt3cbfkizav1r0rybKt.class
I cant even access it inside KotlinMultiplatformExtension
Has anybody ever tried this? Cocoapods config in Gradle Convention Plugin?
b
@Vaibhav Jaiswal did you ever figure this out? I am running into the same problem.
v
Yes, i figured it out I have covered it in my blog