How to use WriteProperties in gradle.build

Hi there, I am a very beginner with gradle and groovy. I’ve managed to create a build file with sweat and tears, that works. I’m creating an ear file that contains a jar and a war inside, from the projects’ sources.

I want to write in a properties file inside the jar the git commits that were used to build the ear file.
I created a method that does that, but the big problem is that it always includes a timestamp.

I want to write the properties without a timestamp, and I’ve found that there is support for that with WriteProperties.

But I don’t have a clue how to translate a method into a task. The method used is this:

	updateVersioningInformation = { versioningPropertiesFile, sourceFolders ->
		def versioningProperties =  new Properties()
		def gitProjects = sourceFolders
		gitProjects.each { subProject ->
			def gitBaseFolder = ['-C', subProject]
			def projectCommit =	new ByteArrayOutputStream()
			exec {
				commandLine = ['git'] + gitBaseFolder + ['log', '--format=\"%H\"', '-n 1']
				standardOutput = projectCommit
			}
			def projectBranch = new ByteArrayOutputStream()
			exec {
				commandLine = ['git'] + gitBaseFolder + ['branch', '--show-current']
				standardOutput = projectBranch
			}
			versioningProperties.setProperty( subProject.substring(subProject.lastIndexOf("/") + 1)  + '.branch', projectBranch.toString().trim());
			versioningProperties.setProperty( subProject.substring(subProject.lastIndexOf("/") + 1) + '.commit', projectCommit.toString().trim().replace('\"',''));
		}
		versioningPropertiesFile.withWriter { versioningProperties.store(it, null) }
		versioningPropertiesFile.with { it.text = it.readLines().findAll { it }.sort().join('\n') }
	}

So what it does is it takes a list of folders where I have the projects, and then writes in a properties file the git commit and branch of that project folder. I call this in a task that is later used as a doFirst when building the jar.

But I want to write the output without the comment line, because if commits don’t change, I don’t want to keep having outgoing files which always end up in conflict.

I don’t have a clue how to apply the WriteProperties task to the method and end up with the same file, basically, comment-less.

I appreciate any help on this

I managed to do something, for other people looking to do the same, this is it.
I’m sure this is a convoluted solution, but ya’ know, better than nothing:
(This is in addition to the code above)

task updateVersioningInformationPropertiesFile(type: WriteProperties) {
  doFirst {
	   	updateVersioningInformation(file('myPath/toFile/Release.properties'), parentProjects)
    }
    outputFile = file('myPath/toFile/Release.properties')

    def props = new Properties()
	file('myPath/toFile/Release.properties').withReader { props.load(it) }
    props.each { prop ->
    	property(prop.key, prop.value)
    }

}

Ta-DAAA