Gradle单对双引号 [英] Gradle Single vs Double Quotes
问题描述
我对gradle很陌生,现在只是试图按照教程进行操作,并且我看过很多次我看过单引号和双引号混合使用。我只是想知道在一套应该用于另一套时是否有差异。其中一个例子是教程的第6.12节 - 默认任务:
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!"
}
所以,我只想知道我是否应该关注这些差异或者它们是可互换的,并且我可以在gradle中打印字符串时使用单引号或双引号。
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.
推荐答案
Gradle构建脚本是用Groovy编写的。 Groovy有双引号和单引号的字符串。主要区别在于双引号的字符串支持字符串插值:
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.
这篇关于Gradle单对双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!