How do I use String interpolation in a Groovy multiline string?

Instead of using ''' for the GString or multi-line string use """

def cretanFood     = "Dakos"  
def mexicanFood    = "Tacos"
def bestRestaurant = """${mexicanFood} & ${cretanFood}"""
print bestRestaurant​

GString enclosed in ''' will not be able to resolve the placeholder - $. You can find more details in the Groovy Documentation under the heading String and String Summary Table block.


In Groovy, single quotes are used to create immutable Strings, just exactly like Java does with double quotes.

When you use double quotes in Groovy you indicate to the runtime your intention to create a mutable String or Groovy String (GString for short). You may use variable interpolation with mutable Strings, or you can leave it as a regular plain Java String.

This behavior extends to the multi-line String versions; usage of triple single quotes creates an immutable multi-line String whereas triple double quotes creates a Groovy String.