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, contains:

name = John
age = 30 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()
   ['',''].each {
      props.load(new FileReader(file(it)))
   def writer = new FileWriter(file(''))
   try {, 'Some comment')
   } finally {

what is


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