Creating your own custom plugin might be a great solution when Gradle doesn’t offer the specific capabilities your project needs. This is where binary plugins come in.

A binary plugin is a plugin that is implemented in a compiled language and is packaged as a JAR file. Binary plugins must implement the Plugin interface.

Implementing the Plugin Interface

For example, this is a very simple "Hello World" plugin:

build.gradle.kts
abstract class SamplePlugin : Plugin<Project> { (1)
    override fun apply(project: Project) {  (2)
        project.tasks.register("ScriptPlugin") {
            doLast {
                println("Hello world from the build file!")
            }
        }
    }
}
build.gradle
class SamplePlugin implements Plugin<Project> { (1)
    void apply(Project project) {   (2)
        project.tasks.register("ScriptPlugin") {
            doLast {
                println("Hello world from the build file!")
            }
        }
    }
}
1 Extend the org.gradle.api.Plugin interface.
2 Override the apply method.

1. Extend the org.gradle.api.Plugin interface

Create a class that extends the Plugin interface:

build.gradle.kts
abstract class SamplePlugin : Plugin<Project> {
}
build.gradle
class SamplePlugin implements Plugin<Project> {
}

2. Override the apply method

Add tasks and other logic in the apply() method:

build.gradle.kts
override fun apply() {
}
build.gradle
void apply(Project project) {
}

Let’s take a look at a more realistic example next.