Apply self-developed gradle plugin

I have developed a gradle plugin and it contains a task DScheck to help analyze the projects. Now i need to run the task on a great number of projects automatically. I want to run the task without editting the projects’ codes just like what i can do in maven. What’s the best practice to do this?

Use an init script that applies the plugin to the project(s).

I tried by adding the below in my init.gralde.

initscript {
    repositories {
        mavenLocal()
        mavenCentral()
    }
    dependencies {
        classpath "com.example:DScheckerGradle:1.0.0"
    }
}
allprojects {
  apply plugin: "com.example.DScheckerGradle"
}

And here’s my plugin’s id definition.

gradlePlugin {
    plugins {
        create("DScheckerGradle"){
            id = "com.example.DScheckerGradle"
            implementationClass = "com.example.DScheckerGradle.gradleplugins.DSchecker"
        }
    }
}

Still, when i try to run the task, it says

* What went wrong:
Plugin with id 'com.example.DScheckerGradle' not found.

Iirc you have to apply by class, not by ID in that case, so

allprojects {
  apply plugin: com.example.DScheckerGradle.gradleplugins.DSchecker
}
1 Like