Use project.configure to implement custom plugin

plugins

(Bart De Neuter) #1

Hi,

I have created a custom plugin. The way I have programmed it, is not documented and I wanted to verify that this way doesn’t have any side effects and is a good way to implement a custom plugin.
In the apply(project) method I call immediatly project.configure project, { ... }. In this lambda function I can configure and program my plugin the same way as in a normal build script. Is it ok to call configure in the apply method? It seems to work as I expected and it keeps my plugin script in line with other build scripts as they use the same high level gradle api’s.

example:

class FormatSourcePlugin implements Plugin<Project> {
  void apply(Project project) {

    project.configure project, {

      apply plugin: "com.diffplug.gradle.spotless"

      // Spotless code formatting
      spotless {
        java {
          googleJavaFormat('1.4')
        }
      }
      compileJava.dependsOn 'spotlessApply'
    }

  }
}