Writing plugins and tasks in groovy or java?


(tulsoba) #1

I have written some of my gradle plugins/tasks in groovy but I am not the big groovy fan (I like typed variables etc.). I have converted some of the tasks to java and it works fine. Are there any pro/cons of writing tasks/plugins in java vs groovy or is it strictly a matter of taste?


(Luke Daley) #2

It’s more or less a matter of taste, but there is one issue…

Gradle decorates many types at runtime via dynamic subclasses. So in effect, there are methods on a lot of objects that you won’t find on its API. If you want to call these methods from Java you’ll need to cast the object to get access to these methods. Because most of this decoration behaviour is related to internal APIs right now this rarely comes up.

As there becomes more of a need for plugin authors to access such functionality we’ll provide more rigorous ways of access it.

If you want more context on what I am talking about, look up ‘DslObject’ in the source code and it’s usages.