I'm trying to generate first plugin but have this error:
Could not find implementation class 'CommonPluginClass' for plugin 'common-plugin' specified in jar:file
org.gradle.api.plugins.InvalidPluginException: An exception occurred applying plugin request [id: 'common-plugin']

this is my CommonPluginClass:
class CommonPluginClass: Plugin<Project> {
override fun apply(project: Project) {
project.task("hello") {
doLast {
println ("Hello from the CommonPluginClass")
}
}
}
}
its very simple. My build.gradle (convention)
plugins {
id 'groovy-gradle-plugin'
}
gradlePlugin {
plugins {
commonPlugin {
id = "common-plugin"
implementationClass = "CommonPluginClass"
}
}
}
and into settings.gradle (build-logic)
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}
}
rootProject.name = "build-logic"
include(":convention")
Into build.gradle (app) i call plugin in this mode:
plugins { id 'common-plugin' }
my exeption:
Maybe it's late
I have faced the same issue and I solved it by moving my plugins folders to the kotlin directory itself and delete the package references from all the plugin classes.

You should basically get this to work by changing the plugins block of your build-logic/convention/build.gradle file to something like the following:
plugins {
id 'java-gradle-plugin'
id 'org.jetbrains.kotlin.jvm' version '1.6.21'
}
I have replicated the relevant bits of your setup as follows (not showing Gradle Wrapper files):
├── app
│ └── build.gradle
├── build-logic
│ ├── convention
│ │ ├── build.gradle
│ │ └── src
│ │ └── main
│ │ └── kotlin
│ │ └── CommonPluginClass.kt
│ └── settings.gradle
└── settings.gradle
The files have the same content as given in your question, except that I’ve changed the files below.
With that, I could successfully run: ./gradlew :app:hello
build-logic/convention/build.gradleplugins {
id 'java-gradle-plugin'
id 'org.jetbrains.kotlin.jvm' version '1.6.21'
}
gradlePlugin {
plugins {
commonPlugin {
id = "common-plugin"
implementationClass = "CommonPluginClass"
}
}
}
build-logic/convention/src/main/kotlin/CommonPluginClass.ktimport org.gradle.api.Project
import org.gradle.api.Plugin
class CommonPluginClass: Plugin<Project> {
override fun apply(project: Project) {
project.task("hello") { t ->
t.doLast {
println ("Hello from the CommonPluginClass")
}
}
}
}
settings.gradlepluginManagement {
includeBuild('build-logic')
}
include ':app'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With