Add dynamic convention properties from a plugin

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

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?

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.

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