I want to include time of build in properties file that is present inside the source code. I currently do it manually by setting current date and time in properties file before WAR generation,
Writing the file with the current timestamp takes some amount of time. Writing a WAR file takes some amount of time. Both can be very small, but there is no way that a WAR file can contain a file that is guaranteed to be the time that the WAR file was created. The elapsed time, even at the smallest measurable increment could cross the minute boundary.
That said, considering information from your other posts, you’re generating the timestamp as soon as the build is configured, not as part of a task action that executes right before the WAR is created. If your trying to tack the property file writing on to the war task, the code inside the war block should also be surrounded with doFirst { } so that it doesn’t run until the war task is running. However, it would be much better if you split this out to a task that only handles the property file or used a filter when the resources are copied as messing with a source file in place isn’t good for UP-TO-DATE checking.