DEV Community

Discussion on: Tony's rules for Gradle plugin authors

Collapse
 
prenagha profile image
Padraic Renaghan

Thanks for the tips. This has given me a few ideas to cleanup my Gradle build...

A couple of questions:

Where I am creating a new configuration, then need to set config.isCanBeConsumed=true, that method on the Provider is now deprecated, and the message says to call get().isCanBeConsumed, but that seems to go against the idea of lazily creating things. Is the get() fine here, or do you suggest something like config.map{ it.isCanBeConsumed=true }?

Also totally missing how map and flatMap differ.

I have a spot where I need to see if a configuration exists already, and if not create it. The problem is I can't seem to find a method to see if something exists that doesn't create/get() the object. the find... methods return T (not Provider), and the named method throws exception if object doesn't exist. I hate to go through the work of using register, only to have the object created too early later when I am only checking to see if it is there.
Is there some way I am missing to see if a named domain object exists without creating it?
The get names looked promising, but there is a lot of work under those covers creating a new TreeMap every time.

Thanks

Collapse
 
autonomousapps profile image
Tony Robalik

You should set things like isCanBeConsumed = true when creating the configuration, so the question of whether to call get() on that Provider is moot.

That said, it's important to understand that, specifically with Configurations, they really aren't ever lazy. This is a case where the "rule" becomes a "guideline." Configurations are always eager, so it's basically OK to use create() and all {} for this type of container.

Also totally missing how map and flatMap differ.

flatMap is when you're mapping over another Provider, so it just "flattens" the provider chain.

I have a spot where I need to see if a configuration exists already, and if not create it.

You can use maybeCreate() for this use-case.

Collapse
 
prenagha profile image
Padraic Renaghan

Thanks for the follow-up