kiruwka
kiruwka

Reputation: 9450

Gradle dependencies groovy closure syntax

Very basic question.

This snapshot in build.gradle :

dependencies {
    classpath 'com.android.tools.build:gradle:0.13.2'
}

is supposed to call method dependencies(Closure c) and pass it a closure.

Could someone please explain the syntax of this simple closure { classpath 'com.android.tools.build:gradle:0.13.2' }

It is not returning anything, is it ?

Upvotes: 1

Views: 1794

Answers (1)

Dave Newton
Dave Newton

Reputation: 160211

http://groovy.codehaus.org/Closures+-+Formal+Definition

Notably:

Closures always return a value. This may occur via either an explicit return statement, or as the value of the last statement in the closure body (e.g. an explicit return statement is optional).

There's not really any syntax to explain; there's a closure, inside it the classpath method is called, and it takes a string argument. Whether or not anything is done with the return value, or whether or not the return value is significant, is a separate issue.

In this case it's not; there's a side-effect of setting the classpath value.

Upvotes: 2

Related Questions