What is the best way to export an object created in settings.gradle to plugin code run from sub-project build.gradle?


(Matias Bjarland) #1

I currently have a groovy @Singleton annotation on the object and can thus create the instance in settings.gradle and call MyClass.instance to retrieve it in build.gradle (or the plugin code as is the case here). This is not pretty and with the multi threaded gradle daemon, CI servers, etc going on, using singleton JVM instances seems like a bad idea.

The object instance in question contains meta data about the multi-project structure and needs to be present configuration time, so something like:

//build.gradle
  apply plugin: 'myplugin'
    allprojects {
    pluginConventionMethod {
      ..
    }
  }

(where the pluginConventionMethod needs the data from the object created in settings.gradle)

should work.

Any help much appreciated.


(Matias Bjarland) #2

Cross linking forum posts. This question has been answered at the following forum post:

What’s the best way to add new methods in settings.gradle files?