[GRADLE-2698] Gradle copy task does not preserve file modification times Created: 06/Mar/13  Updated: 25/Jan/17  Resolved: 25/Jan/17

Status: Resolved
Project: Gradle
Affects Version/s: 1.4
Fix Version/s: None

Type: Bug
Reporter: Daniel Beck Assignee: Unassigned
Resolution: Duplicate Votes: 13


The Gradle copy task does not preserve file modification times even when not changing the file contents.

There should at least be an option to preserve these times.

Comment by Jochen Kemnade [ 04/Dec/14 ]

This still affects 2.2.
AbstractFileTreeElement.copyTo(File) could be extended by target.setLastModified(getLastModified());, but that would make it the default behavior. I'm not sure if that's a good idea.

Comment by Ronald Brindl [ 03/Jun/15 ]

Based on Jochen's comment I did the following workaround.
It records all the FileCopyDetails in a list and applies the dates in doLast. (target files have not been created at execution time of eachFile closure.)

task extractSomeStuff(type: Copy) {
	from zipTree(tasks.createSomeStuff.archivePath)
	destinationDir temporaryDir
	def copyDetails = []
	eachFile { copyDetails << it }
	doLast {
		copyDetails.each { FileCopyDetails details ->
			def target = new File(destinationDir, details.path)
			if(target.exists()) {
Comment by Benjamin Muschko [ 15/Nov/16 ]

As announced on the Gradle blog we are planning to completely migrate issues from JIRA to GitHub.

We intend to prioritize issues that are actionable and impactful while working more closely with the community. Many of our JIRA issues are inactionable or irrelevant. We would like to request your help to ensure we can appropriately prioritize JIRA issues you’ve contributed to.

Please confirm that you still advocate for your JIRA issue before December 10th, 2016 by:

  • Checking that your issues contain requisite context, impact, behaviors, and examples as described in our published guidelines.
  • Leave a comment on the JIRA issue or open a new GitHub issue confirming that the above is complete.

We look forward to collaborating with you more closely on GitHub. Thank you for your contribution to Gradle!

Comment by Jochen Kemnade [ 16/Nov/16 ]

This issue affects Gradle 3.2. I can create a sample Gradle build if you like, but I think the issue should be clear without it.

Comment by Benjamin Muschko [ 24/Jan/17 ]

@Jochen Could you please provide an reproducible example and add it to a new issue on GitHub?

Comment by Jochen Kemnade [ 25/Jan/17 ]


Comment by Benjamin Muschko [ 25/Jan/17 ]

Thanks, @Jochen.

Generated at Wed Jun 30 12:29:03 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.