Another answer gave you a solution that I would also recommend, but it may be helpful to know the reason why this is happening.
Groovy uses excessive operator overload. This means that if you have to write your own class, you can overload the + operator to do a lot of things.
However, there is a difference between using + at the end of the line and at the beginning of the line.
At the end of the line, + considered as an addition, but before the line it is considered as positive (consider that "+ 6" is considered as "positive six").
If you have to write this, this will work better:
println "The row Id is: ${row.id}" + "The word is: ${row.word}" + "The number is: ${row.number}" + "The decimal is: ${row.decimal}" + "The date-time is: ${row.datetime}"
If you do this, you will get the output in one line, because you did not add new string characters, \n
println "The row Id is: ${row.id}\n" + "The word is: ${row.word}\n" + "The number is: ${row.number}\n" + "The decimal is: ${row.decimal}\n" + "The date-time is: ${row.datetime}"
And now everything starts to look ugly, so Groovy's multi-line String functions might come in handy, as shown in another answer.
source share