Silverclaw
Silverclaw

Reputation: 1396

Is Groovy knowledge required to understand Gradle?

So, I've been trying to avoid build tools for a while, but started to use Gradle for some time now. I'm able to use it for simple things like letting it download dependencies, like it's intended, but I've seen people use it to do really advanced staff like manage large projects with different modules, native dependencies, publish to Github when building, etc.

I feel like I still need to copy-paste a lot when trying to do anything more complicated, because even after finding some documentation to read, I'm still not sure where language syntax like {, }, :, (, ), are meant to be used.

So, my question is: Does it make sense to learn Groovy to understand Gradle better? Should reading the docs be enough? I'm not even asking because I would not be interested in Groovy, I'm just wondering how people got used to using Gradle and whether it makes sense to use it for more advanced tasks then fetching dependencies from repositories.

Upvotes: 27

Views: 4937

Answers (2)

tkruse
tkruse

Reputation: 10685

  • To just use Gradle, you can go without understanding Groovy.

  • To understand how a Gradle file syntax works, you definitely need to understand Groovy. People generally struggle with Gradle when scripts become complex.

Gradle uses mostly vanilla Groovy as it's language, but the documentation and most examples use a specific style, that is different from the most conventional style when writing other Groovy code.

But except for a single compiler plugin (for turning some names without quotes into strings), all Gradle code is also valid Groovy code, and you could write any gradle file in the same style as you write any other Groovy file.

Upvotes: 0

JBaruch
JBaruch

Reputation: 22893

Gradle uses DSL (domain specific language) that is currently based on top of Groovy. That means, that you should be able to work with Gradle to some extend by learning the DSL only. It, of course, inherits some of the syntax from Groovy (like the parentheses etc) but the syntax pretty far away from a normal Groovy code.

If you want to start writing your own closures, tasks and plugins then you need some Groovy skills, yes. Groovy in Action 2nd edition is a great book, or if you are a Java developer, take a look at Making Java Groovy.

Saying that, please keep in mind that Gradle Inc announced that they are going to support Kotlin as another language to base the DSL on. It means that you will be able to write the "custom" parts of your build in Kotlin or Groovy. So, keep an eye on Kotlin as well, here's the best way to do it – Kotlin in Action.

Upvotes: 39

Related Questions