Is there a safe, project-isolation-compatible, rec...
# plugin-development
c
Is there a safe, project-isolation-compatible, recommended way to load a property from the root
gradle.properties
file?
v
providers.gradleProperty("...")
I guess?
3
o
v
But as you ask in #CA745PZHN, the answer might also better be, don't query project properties, but register an extension with properties that the consumer can set, or at least only use a conventional project property as convention value for such an extension property. 😄
c
@Vampire I was thinking about that, similar to how I guess gradle loads the BuildFeatures service.
v
Not sure how you mean that? What I said is just normal best practice. Register an extension with properties the consumer can configure and if you really think you need a project property defined by your plugin as default value, wire the
providers.gradleProperty
provider to the property in your extension as
convention
value. But most often you should not even do that, except if it is veeeery likely the consumer wants to set it via project property and if it is of type
String
semantically, because project properties cannot have any other type unlike extension properties.
c
In our case, we've got a plugin whose 'edition' concept we want to change. This changes how the plugin works during the apply phase, which is about as soon as code gets in gradle-land.
v
How about making two plugins? They can be in the same artifact and use the same code, just set some value differently that controls that behavior? Or do you really want that the plugin behaves differently for different users of the same build or even different invocations of the same user? Does not sound like a good idea to me in general.
j
for logic in the configuration phase, providers.gradleProperty is usually the way to go, unless the logic is only using lazy gradle APIs. in that case, it can be an extension