Add dynamic convention properties from a plugin


(Wujek Srujek) #1

I’m writing a plugin, and I would need to be able to add properties to the project based on some runtime conditions, which means that I don’t know the properties when I compile the plugin. I tried to create a convention plugin with the usual Groovy getProperty / setProperty methods, but such properties are not ‘seen’ by the Project (it seems the properties have to be ‘real’ static ones). What are my options? I found: project.getConvention().getExtraProperties().set(…) and project.getExtensions().getExtraProperties().set(…) with getExtensions() actually being getConventions() with a cast. There might be other places better suited for what I’m trying to do. What should I be using for my use case? What is the most stable and reliable place to put my properties?

wujek


(Wujek Srujek) #2

So I’ve noticed that the Gradle-2.0 document in the soruces has been updated, and it seems like ‘convention objects’ will be removed in the future, is this correct? Does this mean we should all be using extensions / extraProperties in new code to minimize the work needed during the Gradle-2.0 move?


(Luke Daley) #3

Does this mean we should all be using extensions / extraProperties in new code to minimize the work needed during the Gradle-2.0 move?

That’s correct.


(Luke Daley) #4

You should use an extension. Your extension can use dynamic tricks such as methodMissing().