User Guide: "keyword style does not work in expressions"


(davidmichaelkarr) #1

Section 15.1, “Defining tasks”, begins with the following:

We have already seen how to define tasks using a keyword style in Chapter 6, Build Script Basics. There are a few variations on this style, which you may need to use in certain situations. For example, the keyword style does not work in expressions.

This paragraph needs some clarification, but I’m having trouble figuring out what was meant to be said.

From the reference to “keyword style” and “chapter 6”, you’d think that chapter 6 would have some mention of “keyword style”. This is not the case. I imagine this means referring to a bare symbol without quotes, but I need to confirm that.

I’m also not sure what is meant by “the keyword style does not work in expressions”. Does that refer to the fact that referencing a “keyword” that isn’t defined as a variable will result in an error?


(Luke Daley) #2

Have asked the original author to comment.


(Hans Dockter) #3

It is long time ago and I can’t fully remember. I think this is what it is about:

Keyword style is:

‘task jar(type: Jar) { … }’

This syntax is not legal Groovy syntax. To make it work we are using AST transforms.

Alternatively you can use an API style that is legal Groovy and does not require AST transforms:

‘tasks.create(name: ‘jar’, type: Jar) { … }’

I can’t come up with an example right now, but there have been programmatic constructs within an build script where you could not use the keyword style and had to use the API style.

BTW: Keyword style and API style is not an established terminology.


(davidmichaelkarr) #4

Ok, this helps. As I knew that “Gradle is just Groovy”, I often wondered about particular Gradle examples, wondering how they could be legal Groovy syntax. Now I understand that they actually weren’t. It might help to document that this “keyword style” is a demonstration of this.

I think I have enough information to clarify this phrasing.