Gradle Plugin Two Step Initialization/Application


I am wondering if there is a standard way for two step plugin initialization. The first step would setup the extension with defaults. The user would then configure the extension as needed, and finally the plugin would complete it’s setup.

Basically I am looking for something like this:

// Suppose myplugin registers the 'mypluginconfig' extension but has other steps
// that need to be run asap before other parts of the build script but require some
// plugin configuration first
apply 'myplugin'
  mypluginconfig {
  // do some configuration
  // TODO Complete myplugin initialization here
  // Now continue on with the script

I suppose I could add an interface with a “completeSetup” method or something but that requires the user to remember to call it:

// Complete myplugin initialization here

I am wondering if these is a standard/better way to do this? Thanks!

There are callbacks such as ‘project.afterEvaluate {}’ and ‘gradle.projectsEvaluated {}’, but there is no such callback as ‘extension.whenConfigured {}’.

I ended up having the plugin be applied in two parts.

// Creates Extension objects and initializes them to their default values
apply from 'myplugin-setup'
  mypluginconfig {
    // custom config
  // Applies the full plugin using the combination of custom configurations and the defaults created by the setup section of the plugin
apply from 'myplugin'