Using a GroovyString for a String property

(Andreas Axelsson) #1

I’ve been using the new lazy properties in my plugin, and they work great, but there’s one small annoyance for users. With regular String task/extension members, you can always assign a GroovyString as is, but when you have a Property, the user needs to manually convert to a String before assigning. It’s probably not too complicated to wrap that somehow, but it’d be great if it was handled automatically by the general Gradle magic that we’ve become accustomed to :slight_smile:

(Schalk Cronjé) #2

In short prefer Object over String in setters and then use something like Grooifan’s StringUtils.stringize in the geteer to do the conversion.

(Andreas Axelsson) #3

That feels a bit counter to how I felt the new Provider<T>/Property<T> system was supposed to work, but I’ve been using Objects for regular tasks/extension properties in the past, so perhaps there’s simply no practical alternative if one wants to support both String and GroovyString in this way.

(Schalk Cronjé) #4

Yes, I can understand some of the reasoning fror Provider & Property. Better lazy-evaluation and support for writing plugins in Java & Kotlin. There is, however, little doubt that it is harming the slickness of the Groovy DSL.