antgroovyantbuilder

AntBuilder ant echo task to append text to a file


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.


Solution

  • Have you tried:

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

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