1

I am running ant task in a groovy file and below is the snippet of it:

def user="USER"
project.ant.echo(file:"/a/b/c/test.properties",  
message:"user=${user}", append="true")

I am trying to append text to the file, by running the script multiple times. However it is not working as expected. Below is the current output:

cat test.properties
user=USERtrue

If the run the groovy file and ant task with append, the file is overwritten and it puts true at the end. If the run the groovy file and ant task without append, the file is simply overwritten.

Not sure what is wrong here. Any help is appreciated.

user1470220
  • 123
  • 2
  • 15

2 Answers2

1

Have you tried:

project.ant.echo( file:"/a/b/c/test.properties",
                  message:"user=${user}",
                  append:true )

ie: use append:true, not append="true"

tim_yates
  • 167,322
  • 27
  • 342
  • 338
  • Cannot believe I have put = instead of :. Apologies for being blind. However the above code appends to the file at the same line, instead of new line. I have done below to append the text to new line everytime. project.ant.echo( file:"/a/b/c/test.properties", message:"\n user=${user}", append:true ) Is there a better way to acheive it? – user1470220 Jan 29 '14 at 10:36
  • @user1470220 Not that I know of if there's no newline at the end of the original file :-( – tim_yates Jan 29 '14 at 10:45
  • @user1470220 could you [accept the comment as an answer](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235) if it solved the problem? Hope it did :-) – tim_yates Jan 29 '14 at 12:15
0

ant.concat can be another option (one less key to give :).

project.ant.concat(destfile:"/some/prop.file", append: true, "user=${user}") 
kdabir
  • 9,623
  • 3
  • 43
  • 45