From 2831cfd43dfb27ebd01c5d36c6ed99bab870860f Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Thu, 13 May 2021 19:38:19 +0100 Subject: [PATCH] strip archives --- build.gradle | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/build.gradle b/build.gradle index 65ff2b31..ac1bb2be 100644 --- a/build.gradle +++ b/build.gradle @@ -34,5 +34,28 @@ subprojects { tasks.withType(AbstractArchiveTask) { preserveFileTimestamps = false reproducibleFileOrder = true + doLast { + stripJar(it.archivePath) + } } } +import java.util.jar.* +void stripJar(File file) { + if (file.getName().endsWith('.tar')) + return + println "stripping $file" + File newFile = new File(file.parent, 'tmp-' + file.name) + newFile.withOutputStream { fout -> + JarOutputStream out = new JarOutputStream(fout) + JarFile jf = new JarFile(file) + jf.entries().unique {it.name}.sort {it.name}.each { + def copy = new JarEntry(it.name) + copy.time = 1001 + out.putNextEntry(copy) + out << jf.getInputStream(it) + } + out.finish() + } + newFile.renameTo file +} +