The custom plugin

In this section, we will discuss how to create a custom plugin. A plugin can be created by implementing the org.gradle.api.Plugin<T> interface. This interface has one method named apply(T target), which must be implemented in the plugin class. Typically, we write a plugin for the Gradle projects. In that situation, T becomes the Project. However, T can be any type of object.

The class that implements the plugin interface can be placed in various locations, such as:

  • The same build file
  • The buildSrc directory
  • A standalone project

This is similar to creating a custom task that we discussed in the last chapter. When we define a plugin in the same build file, the scope is limited to the defining project only. This means, this plugin cannot ...

Get Mastering Gradle now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.