Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle Single vs Double Quotes

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.

like image 259
Dan W Avatar asked Mar 02 '13 05:03

Dan W


People also ask

How do I know if I should use single or double quotes?

If you are an American, using quotation marks could hardly be simpler: Use double quotation marks at all times unless quoting something within a quotation, when you use single.

What is the difference between single and double quotation marks?

General Usage Rules In America, Canada, Australia and New Zealand, the general rule is that double quotes are used to denote direct speech. Single quotes are used to enclose a quote within a quote, a quote within a headline, or a title within a quote.

What is the difference between single and double quotes to delineate strings?

The main difference between double quotes and single quotes is that by using double quotes, you can include variables directly within the string. It interprets the Escape sequences. Each variable will be replaced by its value.

Is there a difference between single and double quotes in Java?

When single quotes bracket a string literal, the value of the literal is the value within the quotes. When double quotes are used, any references to variables or expressions within the quotes are interpolated.


2 Answers

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.

like image 129
Peter Niederwieser Avatar answered Oct 01 '22 05:10

Peter Niederwieser


Yes, you can use one or the other. The only difference is that double-quoted strings can be GStrings, which can contain evaluated expressions like in the following example taken from the Groovy documentation:

foxtype = 'quick' foxcolor = ['b', 'r', 'o', 'w', 'n'] println "The $foxtype ${foxcolor.join()} fox" // => The quick brown fox 
like image 25
JB Nizet Avatar answered Oct 01 '22 04:10

JB Nizet