Hello, I am trying to create a ConventionPlugin wh...
# plugin-development
r
Hello, I am trying to create a ConventionPlugin which is dependent on another external plugin. I have added the plugin as depdency in my
buildSrc/build.gradle.kts
dependencies And this is how I created the convention plugin class
Copy code
import dev.shreyaspatil.composeCompilerMetricsGenerator.plugin.ComposeCompilerReportExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure

class ComposeCompilerReportConventionPlugin: Plugin<Project> {
    override fun apply(target: Project) {
        target.apply {
            plugin("dev.shreyaspatil.compose-compiler-report-generator")
        }
    }


    fun Project.configureComposeCompilerReport(
        reportName: String,
        includeStableInfo: Boolean = false,
        includeAllClassesInfo: Boolean = false,
        includeOnlyUnstableInfo: Boolean = true,
    ) {
        extensions.configure<ComposeCompilerReportExtension> {
            enableMetrics.set(true)
            enableReport.set(true)
            name.set(reportName)
            includeStableComposables.set(includeStableInfo)
            includeStableClasses.set(includeStableInfo)
            includeClasses.set(includeAllClassesInfo)
            showOnlyUnstableComposables.set(includeOnlyUnstableInfo)
        }
    }


}
But when I try to sync I get the error
Copy code
An exception occurred applying plugin request [id: 'com.motive.composecompilerreport']
> Failed to apply plugin 'com.motive.composecompilerreport'.
   > Plugin with id 'dev.shreyaspatil.compose-compiler-report-generator' not found.
FYI, I have also regiseterd the plugin as well
Copy code
gradlePlugin {
    plugins {
        register("composeCompilerReport") {
            id = "com.example.composecompilerreport"
            implementationClass = "ComposeCompilerReportConventionPlugin"
        }
    }
}
m
FYI, I have also regiseterd the plugin as well
That part seemed to have worked well since it's trying to apply
dev.shreyaspatil.compose-compiler-report-generator
Maybe double check the plugin id and/or try to apply using the class instead?
r
Id is correct. What do you mean by applying using class?
m
Copy code
pluginManager.apply(ShreyaspatilPlugin::class.java)
(I think that's the syntax but don't trust me on this)
r
Let me check on this.
j
I bet you can do something like:
Copy code
pluginManager.apply<ShreyaspatilPlugin>()

or maybe just

apply<ShreyaspatilPlugin>()
☝️ 1