Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
33 views
in Technique[技术] by (71.8m points)

groovy - ext and code block's meaning in the gradle file

ext {
    springVersion = "3.1.0.RELEASE"
    emailNotification = "[email protected]"
}

Above code is the snippet of build.gradle

I understand that call ext method with { } closure parameter. it's right? So I think gradle is accessing springVersion and emailNotification. I'm gonna verify my assumption with below code

def ext(data) {
    println data.springVersion
}

ext {
    springVersion = "3.1.0.RELEASE"
    emailNotification = "[email protected]"
}

but run that code below Error occured.

groovy.lang.MissingPropertyException: No such property: springVersion for class: Test

do you explain ext and code block specifically?

See more detail of this Question&Answers :os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

ext is shorthand for project.ext, and is used to define extra properties for the project object. (It's also possible to define extra properties for many other objects.) When reading an extra property, the ext. is omitted (e.g. println project.springVersion or println springVersion). The same works from within methods. It does not make sense to declare a method named ext.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...