3

In the plugin I would like to be able to choose what other plugins apply (e.g. Nexus plugin or Bintray plugin, but not both) based on a configuration placed by a user in the configuration closure for my plugin.

I normally get the configuration for my plugin after the project has been evaluated. That is too late as I would like to allow users to override default configuration for those other plugins in their own (so they have to be applied earlier).

I could split my plugin into two separate plugins (within the same JAR), and require to apply the first one, provide configuration closure, apply the second one and use the configuration provided for the first plugin to decide what 3rd party plugins to apply.

Is there a better way to get the configuration for my plugin early enough to be able to conditionally apply other plugins (and allow them to use their configuration closures)?

Marcin Zajączkowski
  • 4,036
  • 1
  • 32
  • 41

1 Answers1

0

You may use gradle 61.5. Init script plugins. This will allow your plugin runs before project configuration.

Example in the gradle documentation remove repositories from your build script. This means that you can read your configuration in a Init script plugin and decide which plugins to apply. Of course your configuration name should be fixed therefore your Init script plugin should be able to read it.

Atilla Ozgur
  • 14,339
  • 3
  • 49
  • 69
  • But unfortunately I would like to allow users to configure (via the configuration closure) my plugin with the settings which decide if/what plugins will be applied by my plugin. I don't have a clear vision how init script could help me with that. – Marcin Zajączkowski Dec 22 '14 at 23:15
  • The repositories example isn't really the same since it is a live collection and using the `all {}` closure ensures that code is executed for any and all repositories, regardless of when they are configured. There unfortunately isn't a good way (besides `afterEvaluate()`, which OP mentioned) to ensure a project extension has been configured. – Mark Vieira Dec 22 '14 at 23:21