Read & write properties file in my case

I am new in Gradle build script. Say, I have two properties files in my file system. I would like to read all fields in the two properties files & write to a new properties file. How to achieve this in gradle?

For example, file1.properties contains:

name = John
age = 30

file2.properties contains:

gender = male

I would like my build script read all the fields in two files & write to a new file in a different location. That’s new file contains:

name = John
age = 30
gender = male

How to do it in gradle?

task mergePropFiles << {
   def props = new Properties()
   ['file1.properties','file2.properties'].each {
      props.load(new FileReader(file(it)))
   }
   def writer = new FileWriter(file('merged.properties'))
   try {
      props.store(writer, 'Some comment')
      writer.flush()
   } finally {
      writer.close()
   }
}

what is

it

one line 4? Where did you define it?

“it” is an implicit variable in a groovy closure. You can name it if you want to be more verbose http://groovy.codehaus.org/Closures