Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between extra properties and variables in Gradle tasks?

What exactly is difference between these two tasks in Gradle:

task sampleTask {
    String myFile = "sample.txt"
    delete myFile
}

task sampleTask {
    ext.myFile = "sample.txt"
    delete myFile
}

Are they basically the same or do they differ somehow?

like image 956
rfgamaral Avatar asked Jan 13 '23 19:01

rfgamaral


1 Answers

The first snippet declares a local variable which is only visible within the enclosing block. The second snippet adds an extra property that extends Gradle's object model and is visible everywhere the task is visible. Unless you have a reason to extend the object model, use a local variable.

like image 88
Peter Niederwieser Avatar answered May 01 '23 03:05

Peter Niederwieser