Skip to content

Instantly share code, notes, and snippets.

@fuzzyweapon
Created October 13, 2018 01:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fuzzyweapon/9ffb20415afd0a970033039ccc8c20e3 to your computer and use it in GitHub Desktop.
Save fuzzyweapon/9ffb20415afd0a970033039ccc8c20e3 to your computer and use it in GitHub Desktop.
Preserve last modified in copy actions in Gradle without using ant.copy task.
// From https://github.com/gradle/kotlin-dsl/blob/70aca202558f2f6e43cd8ead3ec95d669bfd7b33/build.gradle.kts#L69
// Preserve file modified dates without using ant.copy task
val copyCurrentDistro by task<Copy> {
description = "Copies the current Gradle distro into '$customInstallationDir'."
from(gradle.gradleHomeDir)
into(customInstallationDir)
exclude("**/*kotlin*")
// preserve last modified date on each file to make it easier
// to check which files were patched by next step
val copyDetails = mutableListOf<FileCopyDetails>()
eachFile { copyDetails.add(this) }
doLast {
copyDetails.forEach { details ->
File(customInstallationDir, details.path).setLastModified(details.lastModified)
}
}
// don't bother recreating it
onlyIf { !customInstallationDir.exists() }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment