Newbie Groovy question: looking for a rule of thumb


(Steve Cohen) #1

I’m not a newbie anymore, but some things I’ve glided by without trying to understand - just get the @#$%^ thing to work has been my mantra. Now I’d like to understand a really basic point that has annoyed me. Here is a fragment of build.gradle

sourceCompatibility = 1.6
targetCompatibility = 1.6
war.archiveName 'My.war'

The following does not work.

sourceCompatibility 1.6
targetCompatibility 1.6
war.archiveName 'My.war'

The question is, is there a rule of thumb for knowing (preferably in advance) when a property setting requires the equals operator and when it does not? In this case the sourceCompatibility and targetCompatibility properties require the equals whereas the war.archiveName does not.


(Schalk Cronjé) #2

Good style is to allow both, especially if lists/maps are involved. ON a task there is some code, I believe, that will redirect taskName.propName(value) to taskname.setPropName(value).

But… sourceCompatibility is implemented not on a task but on JavaPluginConvention, which does not have any means of handling missing methods.