GString aware Property/Provider

plugins

(Mikko Värri) #1

Hi,

this is probably best understood by an example, so check this gist

https://gist.github.com/vmj/cd35e27e0253dd24358ebac8df2deaaf

The idea is that the DSL allows setting a suffix (or prefix) that is added to a property of a named domain object.

The syntax for settings the suffix is a bit ugly: "${-> domainName.get() }". Is there a nicer way of doing this?

Additional notes:

  • I’m using properties to avoid requiring strict order of things.
  • If the DSL user is setting the hostName property, i.e. overriding the default, they will need to reapply the prefix/suffix by hand. I’m OK with that.
  • I tried, against the advice of the docs, to implement my own provider that would allow simple syntax: "foo$domainName". But Gradle is apparently expecting providers to extend some internal class, so that was a no-go :smiley: The implementation just looped through GString strings and values, checking if any of the values were instanceof Provider, and calling the value.get() for those.