I'd like to preserve the expected indentation in my source file when using a heredoc but, at the same time, have the contents of the here document not indented when rendered. E.g. the following
// myscript.groovy
if ( someCondition ) {
println """
some multi-line
content
"""
}
will print an indented output e.g.
$ groovy myscript.groovy
some multi-line
content
but instead I'd like it to just print the content unindented as follows
$ groovy myscript.groovy
some multi-line
content
how can this be accomplished in Groovy?
Bash has the <<-STRING
heredoc definition to accomplish this but I've not been able to find anything similar for Groovy.
You need stripMargin
if ( someCondition ) {
println """
|some multi-line
|content
|""". stripMargin()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With