lazybones icon indicating copy to clipboard operation
lazybones copied to clipboard

The String Literal "\n" gets transformed into a new line.

Open AndrewReitz opened this issue 10 years ago • 2 comments

I have out.write("\n"); in a template file. When creating a new project from this template. The out.write("\n"); is changed to

out.write("
");

AndrewReitz avatar Dec 25 '14 05:12 AndrewReitz

This is just one of those things when using the default Groovy template engine. You need to escape any $ and \ in the template. I'll keep this open as a documentation issue.

In your particular case, you can either use out.write("\\n") or switch to Handlebars JavaScript templates, which don't have the same requirement. I lean towards using Handlebars for templates of Java and Groovy source files.

pledbrook avatar Dec 25 '14 08:12 pledbrook

Thanks, this makes a lot of sence. I've been doing replacements in files that have $, but switching the template engine seems a lot easier.

AndrewReitz avatar Dec 25 '14 13:12 AndrewReitz