Gradle Single vs Double Quotes

Dan W picture Dan W · Mar 2, 2013 · Viewed 17.4k times · Source

I'm new to gradle and am currently just trying to follow the tutorials and quite a few times I've seen single and double quotes intermixed. I just wanted to know if there was a difference of when one set should be used over the other. One example of this is section 6.12 of the tutorial - Default tasks:

defaultTasks 'clean', 'run'

task clean << {
    println 'Default Cleaning!'
}

task run << {
    println 'Default Running!'
}

task other << {
    println "I'm not a default task!"
}

So, I would just like to know if I should be paying attention to these differences or if they are inter-changable and I can use either single or double quotes when printing strings in gradle.

Answer

Peter Niederwieser picture Peter Niederwieser · Mar 2, 2013

Gradle build scripts are written in Groovy. Groovy has both double-quoted and single-quoted String literals. The main difference is that double-quoted String literals support String interpolation:

def x = 10
println "result is $x" // prints: result is 10

You can learn more about Groovy String interpolation in this or other Groovy articles on the web.