doFirst not updating WAR file


(malini kennady) #1

In a gradle project, I’m trying to change properties file value before generating WAR in build.gradle as follows,

war {
doFirst {
def propertyFile = file “src/main/resources/properties/about/About.properties"
def props = new Properties()
propertyFile.withReader { props.load(it) }
props.setProperty(‘releaseDate’, new Date().format(“yyyy-MM-dd HH:mm:ss”))
propertyFile.withWriter { props.store(it, null) }
}
rootSpec.exclude(”**/test.jar")
}

But whenever I give build, it generates WAR with previous date time. Say, I’m giving first build at 11:30 and second build at 11:34. The second built WAR contains time as 11:30 instead of 11:34. My intention is to update date whenever WAR is built. Is this way right?