Is Groovy knowledge required to understand Gradle?

时间:2016-07-11 20:57:51

标签: gradle groovy kotlin

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.

2 个答案:

答案 0 :(得分:27)

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.

答案 1 :(得分:0)

  • 要使用Gradle,您可以不了解Groovy。

  • 要了解Gradle文件语法的工作原理,您一定需要了解Groovy。当脚本变得复杂时,人们通常会对Gradle感到困惑。

Gradle主要使用vanilla Groovy作为它的语言,但是文档和大多数示例使用的是特定样式,这与编写其他Groovy代码时的最常规样式不同。

但是除了单个编译器插件(用于将一些没有引号的名称转换为字符串)之外,所有Gradle代码也是有效的Groovy代码,并且您可以使用与编写任何其他Groovy文件相同的样式编写任何gradle文件。 / p>